~ubuntu-branches/ubuntu/lucid/docky/lucid-proposed

« back to all changes in this revision

Viewing changes to Docky.Windowing/Wnck/Window_Extensions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-02-17 15:10:07 UTC
  • Revision ID: james.westby@ubuntu.com-20100217151007-msxpd0lsj300ndde
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  Copyright (C) 2009 Jason Smith
 
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.ComponentModel;
 
21
using System.Runtime.InteropServices;
 
22
using System.Linq;
 
23
using System.Text;
 
24
 
 
25
using Docky.Windowing;
 
26
using Docky.Xlib;
 
27
 
 
28
namespace Wnck
 
29
{
 
30
 
 
31
 
 
32
        public static class Window_Extensions
 
33
        {
 
34
                public static int Area (this Wnck.Window self)
 
35
                {
 
36
                        Gdk.Rectangle geo = self.EasyGeometry ();
 
37
                        return geo.Width * geo.Height;
 
38
                }
 
39
                
 
40
                public static Gdk.Rectangle EasyGeometry (this Window self)
 
41
                {
 
42
                        Gdk.Rectangle geo;
 
43
                        self.GetGeometry (out geo.X, out geo.Y, out geo.Width, out geo.Height);
 
44
                        return geo;
 
45
                }
 
46
                
 
47
                public static void SetWorkaroundGeometry (this Wnck.Window window, WindowGravity gravity, WindowMoveResizeMask mask, 
 
48
                                                     int x, int y, int width, int height)
 
49
                {
 
50
                        // This is very weird.  Don't know when they will fix it. You must subtract the top and left
 
51
                        // frame extents from a move operation to get the window to actually show in the right spot.
 
52
                        // Save for maybe kwin, I think only compiz uses Viewports anyhow, so this is ok.
 
53
                        int [] extents = window.FrameExtents ();
 
54
                        
 
55
                        x -= extents [(int) Position.Left];
 
56
                        y -= extents [(int) Position.Top];
 
57
                        
 
58
                        window.SetGeometry (gravity, mask, x, y, width, height);
 
59
                }
 
60
                
 
61
                public static int [] FrameExtents (this Wnck.Window window)
 
62
                {
 
63
                        return GetCardinalProperty (window, X11Atoms.Instance._NET_FRAME_EXTENTS);
 
64
                }
 
65
                
 
66
                public static int [] GetCardinalProperty (this Wnck.Window window, IntPtr atom)
 
67
                {
 
68
                        X11Atoms atoms = X11Atoms.Instance;
 
69
                        IntPtr display;
 
70
                        IntPtr type;
 
71
                        int format;
 
72
                        IntPtr prop_return;
 
73
                        IntPtr nitems, bytes_after;
 
74
                        int [] extents = new int[12];
 
75
                        
 
76
                        IntPtr window_handle = (IntPtr) window.Xid;
 
77
                        
 
78
                        display = Xlib.GdkDisplayXDisplay (Gdk.Screen.Default.Display);
 
79
                        type = IntPtr.Zero;
 
80
                        
 
81
                        Xlib.XGetWindowProperty (display, window_handle, atom, (IntPtr) 0,
 
82
                                                          (IntPtr) System.Int32.MaxValue, false, atoms.XA_CARDINAL, out type, out format,
 
83
                                                          out nitems, out bytes_after, out prop_return);
 
84
                        
 
85
                        if (type == atoms.XA_CARDINAL && format == 32) {
 
86
                                extents = new int [(int) nitems];
 
87
                                for (int i = 0; i < (int) nitems; i++) {
 
88
                                        extents [i] = Marshal.ReadInt32 (prop_return, i * IntPtr.Size);
 
89
                                }
 
90
                        }
 
91
                        
 
92
                        return extents;
 
93
                }
 
94
        }
 
95
}