~and471/+junk/do-with-docky

« back to all changes in this revision

Viewing changes to Do.Interface.Wink/src/Do.Interface.Wink/WnckWindow_Extensions.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
//  
 
2
//  Copyright (C) 2009 GNOME Do
 
3
// 
 
4
//  This program is free software: you can redistribute it and/or modify
 
5
//  it under the terms of the GNU General Public License as published by
 
6
//  the Free Software Foundation, either version 3 of the License, or
 
7
//  (at your option) any later version.
 
8
// 
 
9
//  This program is distributed in the hope that it will be useful,
 
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
//  GNU General Public License for more details.
 
13
// 
 
14
//  You should have received a copy of the GNU General Public License
 
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
// 
 
17
 
 
18
using System;
 
19
using System.Collections.Generic;
 
20
using System.Linq;
 
21
using System.Runtime.InteropServices;
 
22
 
 
23
using Wnck;
 
24
using Do.Interface.Xlib;
 
25
 
 
26
namespace Do.Interface.Wink
 
27
{
 
28
        
 
29
        
 
30
        public static class WnckWindow_Extensions
 
31
        {
 
32
                public static int Area (this Wnck.Window self)
 
33
                {
 
34
                        Gdk.Rectangle geo = self.EasyGeometry ();
 
35
                        return geo.Width * geo.Height;
 
36
                }
 
37
                
 
38
                public static Gdk.Rectangle EasyGeometry (this Wnck.Window self)
 
39
                {
 
40
                        Gdk.Rectangle geo;
 
41
                        self.GetGeometry (out geo.X, out geo.Y, out geo.Width, out geo.Height);
 
42
                        return geo;
 
43
                }
 
44
                
 
45
                public static void SetWorkaroundGeometry (this Wnck.Window window, WindowGravity gravity, WindowMoveResizeMask mask, 
 
46
                                                     int x, int y, int width, int height)
 
47
                {
 
48
                        // This is very weird.  Don't know when they will fix it. You must subtract the top and left
 
49
                        // frame extents from a move operation to get the window to actually show in the right spot.
 
50
                        // Save for maybe kwin, I think only compiz uses Viewports anyhow, so this is ok.
 
51
                        int [] extents = window.FrameExtents ();
 
52
                        
 
53
                        x -= extents [(int) Position.Left];
 
54
                        y -= extents [(int) Position.Top];
 
55
                        
 
56
                        window.SetGeometry (gravity, mask, x, y, width, height);
 
57
                }
 
58
                
 
59
                public static int [] FrameExtents (this Wnck.Window window)
 
60
                {
 
61
                        return GetCardinalProperty (window, X11Atoms.Instance._NET_FRAME_EXTENTS);
 
62
                }
 
63
                
 
64
                public static int [] GetCardinalProperty (this Wnck.Window window, IntPtr atom)
 
65
                {
 
66
                        X11Atoms atoms = X11Atoms.Instance;
 
67
                        IntPtr display;
 
68
                        IntPtr type;
 
69
                        int format;
 
70
                        IntPtr prop_return;
 
71
                        IntPtr nitems, bytes_after;
 
72
                        int result;
 
73
                        int [] extents = new int[12];
 
74
                        
 
75
                        IntPtr window_handle = (IntPtr) window.Xid;
 
76
                        
 
77
                        display = Xlib.Xlib.GdkDisplayXDisplay (Gdk.Screen.Default.Display);
 
78
                        type = IntPtr.Zero;
 
79
                        
 
80
                        result = Xlib.Xlib.XGetWindowProperty (display, window_handle, atom, (IntPtr) 0,
 
81
                                                          (IntPtr) System.Int32.MaxValue, false, atoms.XA_CARDINAL, out type, out format,
 
82
                                                          out nitems, out bytes_after, out prop_return);
 
83
                        
 
84
                        if (type == atoms.XA_CARDINAL && format == 32) {
 
85
                                extents = new int [(int) nitems];
 
86
                                for (int i = 0; i < (int) nitems; i++) {
 
87
                                        extents [i] = Marshal.ReadInt32 (prop_return, i * IntPtr.Size);
 
88
                                }
 
89
                        }
 
90
                        
 
91
                        return extents;
 
92
                }
 
93
        }
 
94
}