29
29
public static class WindowControl
32
const int SleepTime = 10;
33
35
/// Handles intelligent minimize/restoring of windows. If one or more windows is minimized, it restores
34
36
/// all windows. If more all are visible, it minimizes. This operation only takes into account windows
61
63
public static void MinimizeWindows (IEnumerable<Window> windows)
63
65
foreach (Window window in windows) {
64
if (window.IsInViewport (window.Workspace) && !window.IsMinimized)
66
if (window.IsInViewport (window.Screen.ActiveWorkspace) && !window.IsMinimized) {
65
67
window.Minimize ();
68
System.Threading.Thread.Sleep (SleepTime);
75
79
public static void RestoreWindows (IEnumerable<Window> windows)
77
foreach (Window window in windows) {
78
if (window.IsInViewport (window.Workspace) && window.IsMinimized)
81
foreach (Window window in windows.Reverse ()) {
82
if (window.IsInViewport (window.Screen.ActiveWorkspace) && window.IsMinimized) {
79
83
window.Unminimize (Gtk.Global.CurrentEventTime);
84
System.Threading.Thread.Sleep (SleepTime);
83
89
public static void FocusWindows (IEnumerable<Window> windows)
85
foreach (Window window in windows) {
86
if (window.IsInViewport (window.Workspace) && !window.IsMinimized)
87
window.Activate (Gtk.Global.CurrentEventTime);
91
foreach (Window window in windows.Reverse ()) {
92
if (window.IsInViewport (window.Screen.ActiveWorkspace) && !window.IsMinimized) {
93
window.CenterAndFocusWindow ();
94
System.Threading.Thread.Sleep (SleepTime);
90
98
if (windows.Count () <= 1)
93
101
// we do this to make sure our active window is also at the front... Its a tricky thing to do.
102
// sometimes compiz plays badly. This hacks around it
94
103
uint time = Gtk.Global.CurrentEventTime + 200;
95
104
GLib.Timeout.Add (200, delegate {
96
if (!windows.Any (w => w.IsActive))
98
windows.Where (w => w.IsActive).First ().Activate (time);
105
windows.Where (w => w.IsInViewport (w.Screen.ActiveWorkspace) && !w.IsMinimized).First ().Activate (time);
105
112
FocusWindows (new [] {window});
115
public static void IntelligentFocusOffViewportWindow (Window targetWindow, IEnumerable<Window> additionalWindows)
117
foreach (Window window in additionalWindows.Reverse ()) {
118
if (!window.IsMinimized && WindowsShareViewport (targetWindow, window)) {
119
window.CenterAndFocusWindow ();
120
System.Threading.Thread.Sleep (SleepTime);
124
targetWindow.CenterAndFocusWindow ();
126
if (additionalWindows.Count () <= 1)
129
// we do this to make sure our active window is also at the front... Its a tricky thing to do.
130
// sometimes compiz plays badly. This hacks around it
131
uint time = Gtk.Global.CurrentEventTime + 200;
132
GLib.Timeout.Add (200, delegate {
133
targetWindow.Activate (time);
138
static bool WindowsShareViewport (Wnck.Window first, Wnck.Window second)
140
if (first == null || second == null) return false;
142
Wnck.Workspace wksp = first.Workspace ?? second.Workspace;
143
if (wksp == null) return false;
145
Gdk.Rectangle firstGeo, secondGeo;
147
first.GetGeometry (out firstGeo.X, out firstGeo.Y, out firstGeo.Width, out firstGeo.Height);
148
second.GetGeometry (out secondGeo.X, out secondGeo.Y, out secondGeo.Width, out secondGeo.Height);
150
firstGeo.X += wksp.ViewportX;
151
firstGeo.Y += wksp.ViewportY;
153
secondGeo.X += wksp.ViewportX;
154
secondGeo.Y += wksp.ViewportY;
156
int viewportWidth, viewportHeight;
157
viewportWidth = first.Screen.Width;
158
viewportHeight = first.Screen.Height;
160
int firstViewportX = ((firstGeo.X + firstGeo.Width / 2) / viewportWidth) * viewportWidth;
161
int firstViewportY = ((firstGeo.Y + firstGeo.Height / 2) / viewportHeight) * viewportHeight;
163
Gdk.Rectangle viewpRect = new Gdk.Rectangle (firstViewportX, firstViewportY,
164
viewportWidth, viewportHeight);
166
return viewpRect.IntersectsWith (secondGeo);
108
169
public static void CloseWindows (IEnumerable<Window> windows)
110
171
foreach (Window window in windows.Where (w => !w.IsSkipTasklist))
174
235
scrn.MoveViewport (midX, midY);
177
if (w.Workspace != null && w.Workspace != w.Screen.ActiveWorkspace)
238
if (w.Workspace != null && w.Workspace != w.Screen.ActiveWorkspace)
178
239
w.Workspace.Activate (Gtk.Global.CurrentEventTime);
181
243
w.Unminimize (Gtk.Global.CurrentEventTime);
183
245
w.Activate (Gtk.Global.CurrentEventTime);