~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows/src/Do.Interface/Windowing.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 03:53:12 UTC
  • Revision ID: ootz0rz@gmail.com-20090623035312-it8tb5wkha6nf31p
Added Do.Interface.Windows, and a bunch of cleanup with old MonoDevelop files elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Windowing.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this source distribution.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
using System;
 
21
using System.Threading;
 
22
using System.Diagnostics;
 
23
using System.Collections.Generic;
 
24
using System.Runtime.InteropServices;
 
25
 
 
26
using Gdk;
 
27
using Mono.Unix;
 
28
 
 
29
namespace Do.Interface
 
30
{
 
31
 
 
32
        public static class Windowing
 
33
        {
 
34
 
 
35
                public static void PresentWindow (Gtk.Window window)
 
36
                {
 
37
                        window.Present ();
 
38
                        window.GdkWindow.Raise ();
 
39
 
 
40
                        for (int i = 0; i < 100; i++) {
 
41
                                if (TryGrabWindow (window)) {
 
42
                                        break;
 
43
                                }
 
44
                                Thread.Sleep (100);
 
45
                        }
 
46
                }
 
47
                
 
48
                public static void UnpresentWindow (Gtk.Window window)
 
49
                {
 
50
                        uint time;
 
51
                        time = Gtk.Global.CurrentEventTime;
 
52
                        
 
53
                        Pointer.Ungrab (time);
 
54
                        Keyboard.Ungrab (time);
 
55
                        Gtk.Grab.Remove (window);
 
56
                }
 
57
                
 
58
                private static bool TryGrabWindow (Gtk.Window window)
 
59
                {
 
60
                        uint time;
 
61
 
 
62
                        time = Gtk.Global.CurrentEventTime;
 
63
                        if (Pointer.Grab (window.GdkWindow,
 
64
                                                                                                true,
 
65
                                                                                                EventMask.ButtonPressMask |
 
66
                                                                                                EventMask.ButtonReleaseMask |
 
67
                                                                                                EventMask.PointerMotionMask,
 
68
                                                                                                null,
 
69
                                                                                                null,
 
70
                                                                                                time) == GrabStatus.Success)
 
71
                        {
 
72
                                if (Keyboard.Grab (window.GdkWindow, true, time) == GrabStatus.Success) {
 
73
                                        Gtk.Grab.Add (window);
 
74
                                        return true;
 
75
                                } else {
 
76
                                        Pointer.Ungrab (time);
 
77
                                        return false;
 
78
                                }
 
79
                        }
 
80
                        return false;
 
81
                }
 
82
 
 
83
        }
 
84
}