2
// Copyright (C) 2009 GNOME Do
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.
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.
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/>.
19
using System.Collections.Generic;
21
using System.Runtime.InteropServices;
24
using Do.Interface.Xlib;
26
namespace Do.Interface.Wink
30
public static class WnckWindow_Extensions
32
public static int Area (this Wnck.Window self)
34
Gdk.Rectangle geo = self.EasyGeometry ();
35
return geo.Width * geo.Height;
38
public static Gdk.Rectangle EasyGeometry (this Wnck.Window self)
41
self.GetGeometry (out geo.X, out geo.Y, out geo.Width, out geo.Height);
45
public static void SetWorkaroundGeometry (this Wnck.Window window, WindowGravity gravity, WindowMoveResizeMask mask,
46
int x, int y, int width, int height)
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 ();
53
x -= extents [(int) Position.Left];
54
y -= extents [(int) Position.Top];
56
window.SetGeometry (gravity, mask, x, y, width, height);
59
public static int [] FrameExtents (this Wnck.Window window)
61
return GetCardinalProperty (window, X11Atoms.Instance._NET_FRAME_EXTENTS);
64
public static int [] GetCardinalProperty (this Wnck.Window window, IntPtr atom)
66
X11Atoms atoms = X11Atoms.Instance;
71
IntPtr nitems, bytes_after;
73
int [] extents = new int[12];
75
IntPtr window_handle = (IntPtr) window.Xid;
77
display = Xlib.Xlib.GdkDisplayXDisplay (Gdk.Screen.Default.Display);
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);
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);