1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 
3 #include "config.h"
4 
5 #include <string.h>
6 
7 #include <meta/keybindings.h>
8 
9 #include "cinnamon-wm-private.h"
10 #include "cinnamon-global.h"
11 
12 struct _CinnamonWM {
13   GObject parent;
14 
15   MetaPlugin *plugin;
16 };
17 
18 /* Signals */
19 enum
20 {
21   MINIMIZE,
22   MAXIMIZE,
23   UNMAXIMIZE,
24   TILE,
25   MAP,
26   DESTROY,
27   SWITCH_WORKSPACE,
28   SWITCH_WORKSPACE_COMPLETE,
29   KILL_WINDOW_EFFECTS,
30   SHOW_TILE_PREVIEW,
31   HIDE_TILE_PREVIEW,
32   SHOW_HUD_PREVIEW,
33   HIDE_HUD_PREVIEW,
34 
35   LAST_SIGNAL
36 };
37 
38 G_DEFINE_TYPE(CinnamonWM, cinnamon_wm, G_TYPE_OBJECT);
39 
40 static guint cinnamon_wm_signals [LAST_SIGNAL] = { 0 };
41 
42 static void
cinnamon_wm_init(CinnamonWM * wm)43 cinnamon_wm_init (CinnamonWM *wm)
44 {
45 }
46 
47 static void
cinnamon_wm_finalize(GObject * object)48 cinnamon_wm_finalize (GObject *object)
49 {
50   G_OBJECT_CLASS (cinnamon_wm_parent_class)->finalize (object);
51 }
52 
53 static void
cinnamon_wm_class_init(CinnamonWMClass * klass)54 cinnamon_wm_class_init (CinnamonWMClass *klass)
55 {
56   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
57 
58   gobject_class->finalize = cinnamon_wm_finalize;
59 
60   cinnamon_wm_signals[MINIMIZE] =
61     g_signal_new ("minimize",
62                   G_TYPE_FROM_CLASS (klass),
63                   G_SIGNAL_RUN_LAST,
64                   0,
65                   NULL, NULL, NULL,
66                   G_TYPE_NONE, 1,
67                   META_TYPE_WINDOW_ACTOR);
68   cinnamon_wm_signals[MAXIMIZE] =
69     g_signal_new ("maximize",
70                   G_TYPE_FROM_CLASS (klass),
71                   G_SIGNAL_RUN_LAST,
72                   0,
73                   NULL, NULL, NULL,
74                   G_TYPE_NONE, 5,
75                   META_TYPE_WINDOW_ACTOR, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
76   cinnamon_wm_signals[UNMAXIMIZE] =
77     g_signal_new ("unmaximize",
78                   G_TYPE_FROM_CLASS (klass),
79                   G_SIGNAL_RUN_LAST,
80                   0,
81                   NULL, NULL, NULL,
82                   G_TYPE_NONE, 5,
83                   META_TYPE_WINDOW_ACTOR, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
84   cinnamon_wm_signals[TILE] =
85     g_signal_new ("tile",
86                   G_TYPE_FROM_CLASS (klass),
87                   G_SIGNAL_RUN_LAST,
88                   0,
89                   NULL, NULL, NULL,
90                   G_TYPE_NONE, 5,
91                   META_TYPE_WINDOW_ACTOR, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
92   cinnamon_wm_signals[MAP] =
93     g_signal_new ("map",
94                   G_TYPE_FROM_CLASS (klass),
95                   G_SIGNAL_RUN_LAST,
96                   0,
97                   NULL, NULL, NULL,
98                   G_TYPE_NONE, 1,
99                   META_TYPE_WINDOW_ACTOR);
100   cinnamon_wm_signals[DESTROY] =
101     g_signal_new ("destroy",
102                   G_TYPE_FROM_CLASS (klass),
103                   G_SIGNAL_RUN_LAST,
104                   0,
105                   NULL, NULL, NULL,
106                   G_TYPE_NONE, 1,
107                   META_TYPE_WINDOW_ACTOR);
108   cinnamon_wm_signals[SWITCH_WORKSPACE] =
109     g_signal_new ("switch-workspace",
110 		  G_TYPE_FROM_CLASS (klass),
111 		  G_SIGNAL_RUN_LAST,
112 		  0,
113                   NULL, NULL, NULL,
114                   G_TYPE_NONE, 3,
115                   G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
116   cinnamon_wm_signals[SWITCH_WORKSPACE_COMPLETE] =
117     g_signal_new ("switch-workspace-complete",
118 		  G_TYPE_FROM_CLASS (klass),
119 		  G_SIGNAL_RUN_LAST,
120 		  0,
121 		  NULL, NULL, NULL,
122 		  G_TYPE_NONE, 0);
123   cinnamon_wm_signals[KILL_WINDOW_EFFECTS] =
124     g_signal_new ("kill-window-effects",
125 		  G_TYPE_FROM_CLASS (klass),
126 		  G_SIGNAL_RUN_LAST,
127 		  0,
128 		  NULL, NULL, NULL,
129 		  G_TYPE_NONE, 1,
130 		  META_TYPE_WINDOW_ACTOR);
131     cinnamon_wm_signals[SHOW_TILE_PREVIEW] =
132         g_signal_new ("show-tile-preview",
133                      G_TYPE_FROM_CLASS (klass),
134                      G_SIGNAL_RUN_LAST,
135                      0, NULL, NULL, NULL,
136                      G_TYPE_NONE, 4,
137                      META_TYPE_WINDOW,
138                      META_TYPE_RECTANGLE,
139                      G_TYPE_INT,
140                      G_TYPE_UINT);
141     cinnamon_wm_signals[HIDE_TILE_PREVIEW] =
142         g_signal_new ("hide-tile-preview",
143                      G_TYPE_FROM_CLASS (klass),
144                      G_SIGNAL_RUN_LAST,
145                      0,
146                      NULL, NULL, NULL,
147                      G_TYPE_NONE, 0);
148     cinnamon_wm_signals[SHOW_HUD_PREVIEW] =
149         g_signal_new ("show-hud-preview",
150                      G_TYPE_FROM_CLASS (klass),
151                      G_SIGNAL_RUN_LAST,
152                      0,
153                      NULL, NULL, NULL,
154                      G_TYPE_NONE, 3,
155                      G_TYPE_UINT,
156                      META_TYPE_RECTANGLE,
157                      G_TYPE_UINT);
158     cinnamon_wm_signals[HIDE_HUD_PREVIEW] =
159         g_signal_new ("hide-hud-preview",
160                      G_TYPE_FROM_CLASS (klass),
161                      G_SIGNAL_RUN_LAST,
162                      0,
163                      NULL, NULL, NULL,
164                      G_TYPE_NONE, 0);
165 }
166 
167 void
_cinnamon_wm_switch_workspace(CinnamonWM * wm,gint from,gint to,MetaMotionDirection direction)168 _cinnamon_wm_switch_workspace (CinnamonWM      *wm,
169                             gint          from,
170                             gint          to,
171                             MetaMotionDirection direction)
172 {
173   g_signal_emit (wm, cinnamon_wm_signals[SWITCH_WORKSPACE], 0,
174                  from, to, direction);
175 }
176 
177 /**
178  * cinnamon_wm_completed_switch_workspace:
179  * @wm: the CinnamonWM
180  *
181  * The plugin must call this when it has finished switching the
182  * workspace.
183  **/
184 void
cinnamon_wm_completed_switch_workspace(CinnamonWM * wm)185 cinnamon_wm_completed_switch_workspace (CinnamonWM *wm)
186 {
187   meta_plugin_switch_workspace_completed (wm->plugin);
188   g_signal_emit (wm, cinnamon_wm_signals[SWITCH_WORKSPACE_COMPLETE], 0);
189 }
190 
191 /**
192  * cinnamon_wm_completed_minimize:
193  * @wm: the CinnamonWM
194  * @actor: the MetaWindowActor actor
195  *
196  * The plugin must call this when it has completed a window minimize effect.
197  **/
198 void
cinnamon_wm_completed_minimize(CinnamonWM * wm,MetaWindowActor * actor)199 cinnamon_wm_completed_minimize (CinnamonWM         *wm,
200                              MetaWindowActor *actor)
201 {
202   meta_plugin_minimize_completed (wm->plugin, actor);
203 }
204 
205 /**
206  * cinnamon_wm_completed_maximize:
207  * @wm: the CinnamonWM
208  * @actor: the MetaWindowActor actor
209  *
210  * The plugin must call this when it has completed a window maximize effect.
211  **/
212 void
cinnamon_wm_completed_maximize(CinnamonWM * wm,MetaWindowActor * actor)213 cinnamon_wm_completed_maximize (CinnamonWM         *wm,
214                              MetaWindowActor *actor)
215 {
216   meta_plugin_maximize_completed (wm->plugin, actor);
217 }
218 
219 /**
220  * cinnamon_wm_completed_tile:
221  * @wm: the CinnamonWM
222  * @actor: the MetaWindowActor actor
223  *
224  * The plugin must call this when it has completed a window tile effect.
225  **/
226 void
cinnamon_wm_completed_tile(CinnamonWM * wm,MetaWindowActor * actor)227 cinnamon_wm_completed_tile  (CinnamonWM         *wm,
228                              MetaWindowActor *actor)
229 {
230   meta_plugin_tile_completed (wm->plugin, actor);
231 }
232 
233 
234 /**
235  * cinnamon_wm_completed_unmaximize:
236  * @wm: the CinnamonWM
237  * @actor: the MetaWindowActor actor
238  *
239  * The plugin must call this when it has completed a window unmaximize effect.
240  **/
241 void
cinnamon_wm_completed_unmaximize(CinnamonWM * wm,MetaWindowActor * actor)242 cinnamon_wm_completed_unmaximize (CinnamonWM         *wm,
243                                MetaWindowActor *actor)
244 {
245   meta_plugin_unmaximize_completed (wm->plugin, actor);
246 }
247 
248 /**
249  * cinnamon_wm_completed_map:
250  * @wm: the CinnamonWM
251  * @actor: the MetaWindowActor actor
252  *
253  * The plugin must call this when it has completed a window map effect.
254  **/
255 void
cinnamon_wm_completed_map(CinnamonWM * wm,MetaWindowActor * actor)256 cinnamon_wm_completed_map (CinnamonWM         *wm,
257                         MetaWindowActor *actor)
258 {
259   meta_plugin_map_completed (wm->plugin, actor);
260 }
261 
262 /**
263  * cinnamon_wm_completed_destroy:
264  * @wm: the CinnamonWM
265  * @actor: the MetaWindowActor actor
266  *
267  * The plugin must call this when it has completed a window destroy effect.
268  **/
269 void
cinnamon_wm_completed_destroy(CinnamonWM * wm,MetaWindowActor * actor)270 cinnamon_wm_completed_destroy (CinnamonWM         *wm,
271                             MetaWindowActor *actor)
272 {
273   meta_plugin_destroy_completed (wm->plugin, actor);
274 }
275 
276 void
_cinnamon_wm_kill_window_effects(CinnamonWM * wm,MetaWindowActor * actor)277 _cinnamon_wm_kill_window_effects (CinnamonWM         *wm,
278                                MetaWindowActor *actor)
279 {
280   g_signal_emit (wm, cinnamon_wm_signals[KILL_WINDOW_EFFECTS], 0, actor);
281 }
282 
283 void
_cinnamon_wm_show_tile_preview(CinnamonWM * wm,MetaWindow * window,MetaRectangle * tile_rect,int tile_monitor,guint snap_queued)284 _cinnamon_wm_show_tile_preview (CinnamonWM      *wm,
285                                 MetaWindow      *window,
286                                 MetaRectangle   *tile_rect,
287                                 int             tile_monitor,
288                                 guint           snap_queued)
289 {
290     g_signal_emit (wm, cinnamon_wm_signals[SHOW_TILE_PREVIEW], 0,
291                    window, tile_rect, tile_monitor, snap_queued);
292 }
293 
294 void
_cinnamon_wm_hide_tile_preview(CinnamonWM * wm)295 _cinnamon_wm_hide_tile_preview (CinnamonWM *wm)
296 {
297     g_signal_emit (wm, cinnamon_wm_signals[HIDE_TILE_PREVIEW], 0);
298 }
299 
300 void
_cinnamon_wm_show_hud_preview(CinnamonWM * wm,guint current_proximity_zone,MetaRectangle * work_area,guint snap_queued)301 _cinnamon_wm_show_hud_preview (CinnamonWM       *wm,
302                                guint            current_proximity_zone,
303                                MetaRectangle    *work_area,
304                                guint            snap_queued)
305 {
306     g_signal_emit (wm, cinnamon_wm_signals[SHOW_HUD_PREVIEW], 0,
307                    current_proximity_zone, work_area, snap_queued);
308 }
309 
310 void
_cinnamon_wm_hide_hud_preview(CinnamonWM * wm)311 _cinnamon_wm_hide_hud_preview (CinnamonWM *wm)
312 {
313     g_signal_emit (wm, cinnamon_wm_signals[HIDE_HUD_PREVIEW], 0);
314 }
315 
316 void
_cinnamon_wm_minimize(CinnamonWM * wm,MetaWindowActor * actor)317 _cinnamon_wm_minimize (CinnamonWM         *wm,
318                     MetaWindowActor *actor)
319 {
320   g_signal_emit (wm, cinnamon_wm_signals[MINIMIZE], 0, actor);
321 }
322 
323 void
_cinnamon_wm_maximize(CinnamonWM * wm,MetaWindowActor * actor,int target_x,int target_y,int target_width,int target_height)324 _cinnamon_wm_maximize (CinnamonWM         *wm,
325                     MetaWindowActor *actor,
326                     int              target_x,
327                     int              target_y,
328                     int              target_width,
329                     int              target_height)
330 {
331   g_signal_emit (wm, cinnamon_wm_signals[MAXIMIZE], 0, actor, target_x, target_y, target_width, target_height);
332 }
333 
334 void
_cinnamon_wm_unmaximize(CinnamonWM * wm,MetaWindowActor * actor,int target_x,int target_y,int target_width,int target_height)335 _cinnamon_wm_unmaximize (CinnamonWM         *wm,
336                       MetaWindowActor *actor,
337                       int              target_x,
338                       int              target_y,
339                       int              target_width,
340                       int              target_height)
341 {
342   g_signal_emit (wm, cinnamon_wm_signals[UNMAXIMIZE], 0, actor, target_x, target_y, target_width, target_height);
343 }
344 
345 void
_cinnamon_wm_tile(CinnamonWM * wm,MetaWindowActor * actor,int target_x,int target_y,int target_width,int target_height)346 _cinnamon_wm_tile (CinnamonWM         *wm,
347                    MetaWindowActor    *actor,
348                    int                 target_x,
349                    int                 target_y,
350                    int                 target_width,
351                    int                 target_height)
352 {
353   g_signal_emit (wm, cinnamon_wm_signals[TILE], 0, actor, target_x, target_y, target_width, target_height);
354 }
355 
356 void
_cinnamon_wm_map(CinnamonWM * wm,MetaWindowActor * actor)357 _cinnamon_wm_map (CinnamonWM         *wm,
358                MetaWindowActor *actor)
359 {
360   g_signal_emit (wm, cinnamon_wm_signals[MAP], 0, actor);
361 }
362 
363 void
_cinnamon_wm_destroy(CinnamonWM * wm,MetaWindowActor * actor)364 _cinnamon_wm_destroy (CinnamonWM         *wm,
365                    MetaWindowActor *actor)
366 {
367   g_signal_emit (wm, cinnamon_wm_signals[DESTROY], 0, actor);
368 }
369 
370 /**
371  * cinnamon_wm_new:
372  * @plugin: the #MetaPlugin
373  *
374  * Creates a new window management interface by hooking into @plugin.
375  *
376  * Return value: the new window-management interface
377  **/
378 CinnamonWM *
cinnamon_wm_new(MetaPlugin * plugin)379 cinnamon_wm_new (MetaPlugin *plugin)
380 {
381   CinnamonWM *wm;
382 
383   wm = g_object_new (CINNAMON_TYPE_WM, NULL);
384   wm->plugin = plugin;
385 
386   return wm;
387 }
388 
389