~and471/+junk/do-with-docky

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/DockWindow.cs

  • Committer: rugby471 at gmail
  • Date: 2010-10-15 16:08:38 UTC
  • Revision ID: rugby471@gmail.com-20101015160838-z9m3utbf7bxzb5ty
reverted to before docky removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DockWindow.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Linq;
 
22
 
 
23
using Gdk;
 
24
using Gtk;
 
25
using Cairo;
 
26
 
 
27
using Docky.Utilities;
 
28
 
 
29
using Do.Universe;
 
30
using Do.Platform;
 
31
using Do.Platform.Linux;
 
32
using Do.Interface;
 
33
using Do.Interface.Xlib;
 
34
using Do.Interface.CairoUtils;
 
35
using Do.Interface.AnimationBase;
 
36
 
 
37
namespace Docky.Interface
 
38
{
 
39
        
 
40
        
 
41
        public class DockWindow : Gtk.Window, IDoWindow, IConfigurable
 
42
        {
 
43
                public static Gtk.Window Window { get; private set; }
 
44
                
 
45
                BezelGlassResults results;
 
46
                BezelGlassWindow results_window;
 
47
                
 
48
                DockArea dock_area;
 
49
                Interface.DoInteropService interop_service;
 
50
                IDoController controller;
 
51
                Gdk.Rectangle current_mask, blur_mask;
 
52
                
 
53
                uint strut_timer;
 
54
                bool presented;
 
55
                int buffer_x, buffer_y;
 
56
                int buffer_width, buffer_height;
 
57
                
 
58
                public new string Name {
 
59
                        get { return "Docky"; }
 
60
                }
 
61
                
 
62
                public IDoController Controller {
 
63
                        get { return controller; }
 
64
                }
 
65
                
 
66
                public DockWindow () : base (Gtk.WindowType.Toplevel)
 
67
                {
 
68
                        Window = this;
 
69
                }
 
70
                
 
71
                public void Initialize (IDoController controller)
 
72
                {
 
73
                        this.controller = controller;
 
74
                        controller.Orientation = ControlOrientation.Vertical;
 
75
 
 
76
                        interop_service = new DoInteropService (controller);
 
77
                        Core.DockServices.RegisterService (interop_service);
 
78
                        
 
79
                        Core.DockServices.PainterService.RegisterPainter (new Painters.SummonModeRenderer ());
 
80
                        
 
81
                        RegisterEvents ();
 
82
                        Build ();
 
83
                }
 
84
                
 
85
                void Build ()
 
86
                {
 
87
                        AppPaintable = true;
 
88
                        AcceptFocus = false;
 
89
                        Decorated = false;
 
90
                        SkipPagerHint = true;
 
91
                        SkipTaskbarHint = true;
 
92
                        Resizable = false;
 
93
                        CanFocus = false;
 
94
                        TypeHint = WindowTypeHint.Dock;
 
95
                        
 
96
                        this.SetCompositeColormap ();
 
97
                        
 
98
                        dock_area = new DockArea (this);
 
99
                        Add (dock_area);
 
100
 
 
101
                        results = new BezelGlassResults (controller, 450, HUDStyle.Classic, new BezelColors (new Cairo.Color (.1, .1, .1, .8)));
 
102
                        results.SlideFromBottom = DockPreferences.Orientation == DockOrientation.Bottom;
 
103
                        results_window = new BezelGlassWindow (results);
 
104
 
 
105
                        ShowAll ();
 
106
                        Stick ();
 
107
                }
 
108
                
 
109
                void RegisterEvents ()
 
110
                {
 
111
                        Realized += (o, a) => GdkWindow.SetBackPixmap (null, false);
 
112
        
 
113
                        StyleSet += HandleStyleSet;
 
114
                        
 
115
                        Screen.Default.SizeChanged += HandleSizeChanged;
 
116
                        DockPreferences.AllowOverlapChanged += DelaySetStruts;
 
117
                        DockPreferences.AutohideChanged += DelaySetStruts;
 
118
                        DockPreferences.MonitorChanged += HandleMonitorChanged;
 
119
                }
 
120
 
 
121
                void UnregisterEvents ()
 
122
                {
 
123
                        StyleSet -= HandleStyleSet;
 
124
                        
 
125
                        Screen.Default.SizeChanged -= HandleSizeChanged;
 
126
                        DockPreferences.AllowOverlapChanged -= DelaySetStruts;
 
127
                        DockPreferences.AutohideChanged -= DelaySetStruts;
 
128
                        DockPreferences.MonitorChanged -= HandleMonitorChanged;
 
129
 
 
130
                        if (strut_timer > 0)
 
131
                                GLib.Source.Remove (strut_timer);
 
132
                }
 
133
 
 
134
                void HandleSizeChanged (object o, EventArgs args)
 
135
                {
 
136
                        LayoutUtils.Recalculate ();
 
137
                        Reposition ();
 
138
                        DelaySetStruts ();
 
139
                }
 
140
 
 
141
                void HandleMonitorChanged ()
 
142
                {
 
143
                        // bring us back down to "minimum" size
 
144
                        Resize (1, 1);
 
145
                        DelaySetStruts ();
 
146
                }
 
147
                
 
148
                void HandleStyleSet (object o, StyleSetArgs args)
 
149
                {
 
150
                        if (!IsRealized) return;
 
151
                        
 
152
                        GdkWindow.SetBackPixmap (null, false);
 
153
                        
 
154
                        Gdk.Rectangle tmp = current_mask;
 
155
                        current_mask = Gdk.Rectangle.Zero;
 
156
                        
 
157
                        SetInputMask (tmp);
 
158
                }
 
159
                
 
160
                public void SetInputMask (Gdk.Rectangle area)
 
161
                {
 
162
                        if (!IsRealized || current_mask == area)
 
163
                                return;
 
164
 
 
165
                        current_mask = area;
 
166
                        if (area.Width == 0 || area.Height == 0) {
 
167
                                InputShapeCombineMask (null, 0, 0);
 
168
                                return;
 
169
                        }
 
170
 
 
171
                        Gdk.Pixmap pixmap = new Gdk.Pixmap (null, area.Width, area.Height, 1);
 
172
                        Context cr = Gdk.CairoHelper.Create (pixmap);
 
173
                        
 
174
                        cr.Color = new Cairo.Color (0, 0, 0, 1);
 
175
                        cr.Paint ();
 
176
 
 
177
                        InputShapeCombineMask (pixmap, area.X, area.Y);
 
178
                        
 
179
                        (cr as IDisposable).Dispose ();
 
180
                        pixmap.Dispose ();
 
181
                }
 
182
                
 
183
                protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
 
184
                {
 
185
                        Gdk.Rectangle rect;
 
186
                        GetSize (out rect.Width, out rect.Height);
 
187
                        GetPosition (out rect.X, out rect.Y);
 
188
                        
 
189
                        if (!rect.Contains ((int) evnt.XRoot, (int) evnt.YRoot)) {
 
190
                                dock_area.ProxyButtonReleaseEvent (evnt);
 
191
                        }
 
192
                        
 
193
                        return base.OnButtonReleaseEvent (evnt);
 
194
                }
 
195
                
 
196
                protected override bool OnConfigureEvent (Gdk.EventConfigure evnt)
 
197
                {
 
198
                        buffer_x = evnt.X;
 
199
                        buffer_y = evnt.Y;
 
200
                        return base.OnConfigureEvent (evnt);
 
201
                }
 
202
 
 
203
                
 
204
                protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
 
205
                {
 
206
                        if (Visible || dock_area.PainterOverlayVisible)
 
207
                                KeyPressEvent (evnt);
 
208
                        return base.OnKeyPressEvent (evnt);
 
209
                }
 
210
 
 
211
                
 
212
                protected override void OnShown ()
 
213
                {
 
214
                        base.OnShown ();
 
215
                        Reposition ();
 
216
                        
 
217
                        SetStruts ();
 
218
                }
 
219
                
 
220
                protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
221
                {
 
222
                        buffer_width = allocation.Width;
 
223
                        buffer_height = allocation.Height;
 
224
                        
 
225
                        base.OnSizeAllocated (allocation);
 
226
                        Reposition ();
 
227
                }
 
228
                
 
229
                public void Reposition ()
 
230
                {
 
231
                        Gdk.Rectangle geo, main, res;
 
232
                        
 
233
                        GetSize (out main.Width, out main.Height);
 
234
                        results_window.GetSize (out res.Width, out res.Height);
 
235
                        geo = LayoutUtils.MonitorGeometry ();
 
236
 
 
237
                        switch (DockPreferences.Orientation) {
 
238
                        case DockOrientation.Bottom:
 
239
                                Move ((geo.X + geo.Width / 2) - main.Width / 2, geo.Y + geo.Height - main.Height);
 
240
                                results_window.Move ((geo.X + geo.Width / 2) - res.Width / 2, geo.Y + geo.Height - dock_area.DockHeight - res.Height);
 
241
                                break;
 
242
                        case DockOrientation.Top:
 
243
                                Move (geo.X, geo.Y);
 
244
                                results_window.Move ((geo.X + geo.Width / 2) - res.Width / 2, geo.Y + dock_area.DockHeight);
 
245
                                break;
 
246
                        }
 
247
                        
 
248
                        results.SlideFromBottom = DockPreferences.Orientation == DockOrientation.Bottom;
 
249
                }
 
250
                                
 
251
                public void GetBufferedPosition (out int x, out int y)
 
252
                {
 
253
                        if (buffer_x == 0 && buffer_y == 0)
 
254
                                GetPosition (out buffer_x, out buffer_y);
 
255
                        x = buffer_x;
 
256
                        y = buffer_y;
 
257
                }
 
258
                
 
259
                public void GetBufferedSize (out int width, out int height)
 
260
                {
 
261
                        if (buffer_width == 0 && buffer_height == 0)
 
262
                                GetSize (out buffer_width, out buffer_height);
 
263
                        width = buffer_width;
 
264
                        height = buffer_height;
 
265
                }
 
266
                
 
267
                public void DelaySetStruts ()
 
268
                {
 
269
                        if (strut_timer > 0)
 
270
                                return;
 
271
                        
 
272
                        strut_timer = GLib.Timeout.Add (250, SetStruts);
 
273
                }
 
274
                
 
275
                public bool SetStruts ()
 
276
                {
 
277
                        X11Atoms atoms = X11Atoms.Instance;
 
278
 
 
279
                        IntPtr [] struts = dock_area.StrutRequest.Select (i => (IntPtr) i).ToArray ();
 
280
                        IntPtr [] first_struts = new [] { struts [0], struts [1], struts [2], struts [3] };
 
281
 
 
282
                        strut_timer = 0;
 
283
                        
 
284
                        if (!IsRealized)
 
285
                                return false;
 
286
                        Xlib.XChangeProperty (GdkWindow, atoms._NET_WM_STRUT_PARTIAL, atoms.XA_CARDINAL,
 
287
                                              (int) PropertyMode.PropModeReplace, struts);
 
288
                        
 
289
                        Xlib.XChangeProperty (GdkWindow, atoms._NET_WM_STRUT, atoms.XA_CARDINAL, 
 
290
                                              (int) PropertyMode.PropModeReplace, first_struts);
 
291
                                
 
292
                        return false;
 
293
                }
 
294
                
 
295
                public void SetBackgroundBlur (Gdk.Rectangle area)
 
296
                {
 
297
                        if (!IsRealized || blur_mask == area)
 
298
                                return;
 
299
                        
 
300
                        blur_mask = area;
 
301
                        
 
302
                        int WindowHeight = dock_area.Height;
 
303
                        X11Atoms atoms = X11Atoms.Instance;
 
304
                
 
305
                        IntPtr [] data = new IntPtr [8];
 
306
                        
 
307
                        // this is meant to tell the blur-plugin what and how to blur, somehow
 
308
                        // the y-coords are interpreted as being CenterGravity, I wonder why
 
309
                        // Kudos to macslow
 
310
                        data [0] = (IntPtr) 2;                                   // threshold
 
311
                        data [1] = (IntPtr) 0;                                   // filter
 
312
                        data [2] = (IntPtr) XGravity.NorthWestGravity;           // gravity of top-left
 
313
                        data [3] = (IntPtr) area.X;                              // x-coord of top-left
 
314
                        data [4] = (IntPtr) (WindowHeight / 2 - area.Height);    // y-coord of top-left
 
315
                        data [5] = (IntPtr) XGravity.NorthWestGravity;           // gravity of bottom-right
 
316
                        data [6] = (IntPtr) (area.X + area.Width);               // bottom-right x-coord
 
317
                        data [7] = (IntPtr) (WindowHeight / 2);                  // bottom-right y-coord
 
318
                        
 
319
                        Xlib.XChangeProperty (GdkWindow, atoms._COMPIZ_WM_WINDOW_BLUR, atoms.XA_INTEGER, (int) PropertyMode.PropModeReplace, data);
 
320
                }
 
321
 
 
322
                public void PresentWindow ()
 
323
                {
 
324
                        if (!presented)
 
325
                                Windowing.PresentWindow (this);
 
326
                        
 
327
                        presented = true;
 
328
                }
 
329
                
 
330
                public void UnpresentWindow ()
 
331
                {
 
332
                        if (presented)
 
333
                                Windowing.UnpresentWindow (this);
 
334
                        
 
335
                        presented = false;
 
336
                }
 
337
                
 
338
                #region IDoWindow implementation 
 
339
                
 
340
                public new event DoEventKeyDelegate KeyPressEvent;
 
341
                
 
342
                public void Summon ()
 
343
                {
 
344
                        Visible = true;
 
345
                        results_window.Show ();
 
346
                        Reposition ();
 
347
                        PresentWindow ();
 
348
                        interop_service.SignalSummon ();
 
349
                }
 
350
                
 
351
                public void Vanish ()
 
352
                {
 
353
                        Visible = false;
 
354
                        UnpresentWindow ();
 
355
                        results_window.Hide ();
 
356
                        interop_service.SignalVanish ();
 
357
                }
 
358
                
 
359
                public void Reset ()
 
360
                {
 
361
                        DockState.Instance.Clear ();
 
362
                        results.Clear ();
 
363
                        interop_service.SignalReset ();
 
364
                }
 
365
                
 
366
                public void Grow ()
 
367
                {
 
368
                        DockState.Instance.ThirdPaneVisible = true;
 
369
                }
 
370
                
 
371
                public void Shrink ()
 
372
                {
 
373
                        DockState.Instance.ThirdPaneVisible = false;
 
374
                }
 
375
                
 
376
                public void GrowResults ()
 
377
                {
 
378
                        results.SlideIn ();
 
379
                        interop_service.SignalResultsGrow ();
 
380
                }
 
381
                
 
382
                public void ShrinkResults ()
 
383
                {
 
384
                        results.SlideOut ();
 
385
                        interop_service.SignalResultsShrink ();
 
386
                        
 
387
                }
 
388
                
 
389
                public void SetPaneContext (Pane pane, IUIContext context)
 
390
                {
 
391
                        DockState.Instance.SetContext (context, pane);
 
392
                        if (CurrentPane == pane) {
 
393
                                results.Context = context;
 
394
                        }
 
395
                }
 
396
                
 
397
                public void ClearPane (Pane pane)
 
398
                {
 
399
                        DockState.Instance.ClearPane (pane);
 
400
                }
 
401
                
 
402
                public new bool Visible {
 
403
                        get; private set;
 
404
                }
 
405
                
 
406
                public Pane CurrentPane {
 
407
                        get { return DockState.Instance.CurrentPane; }
 
408
                        set { DockState.Instance.CurrentPane = value; }
 
409
                }
 
410
                
 
411
                public bool ResultsCanHide { 
 
412
                        get { return true; } 
 
413
                }
 
414
                
 
415
                public override void Dispose ()
 
416
                {
 
417
                        Window = null;
 
418
                        UnregisterEvents ();
 
419
 
 
420
                        Remove (dock_area);
 
421
                        dock_area.Dispose ();
 
422
                        dock_area.Destroy ();
 
423
                        dock_area = null;
 
424
                        
 
425
                        Core.DockServices.Clean ();
 
426
                        
 
427
                        Destroy ();
 
428
                        base.Dispose ();
 
429
                }
 
430
 
 
431
 
 
432
                #endregion 
 
433
 
 
434
                #region IConfigurable implementation
 
435
                public Bin GetConfiguration ()
 
436
                {
 
437
                        return new DockyConfigurationWidget ();
 
438
                }
 
439
                
 
440
                public string Description {
 
441
                        get {
 
442
                                return "Docky configuration";
 
443
                        }
 
444
                }
 
445
                
 
446
                public new string Icon {
 
447
                        get {
 
448
                                return "panel";
 
449
                        }
 
450
                }
 
451
                #endregion
 
452
        }
 
453
}