~jejones/do/future-actionsource

« back to all changes in this revision

Viewing changes to Do.Addins/src/Do.UI/MonoDock/MonoDock.Util/WindowUtils.cs

  • Committer: Jason Jones
  • Date: 2008-11-23 10:59:09 UTC
  • mfrom: (565.1.59 do)
  • Revision ID: jasonedwardjones@gmail.com-20081123105909-yrkn0y7zip76gvj3
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
using System;
20
20
using System.Collections.Generic;
21
21
using System.IO;
 
22
using System.Linq;
22
23
 
23
24
using Do.Addins;
24
25
using Do.Universe;
42
43
                        return apps.ToArray ();
43
44
                }
44
45
                
 
46
                public static string CmdLineForPid (int pid)
 
47
                {
 
48
                        StreamReader reader;
 
49
                        try {
 
50
                                reader = new StreamReader (Do.Paths.Combine ("/proc", pid.ToString (), "cmdline"));
 
51
                        } catch { return null; }
 
52
                        
 
53
                        string cmdline = reader.ReadLine ();
 
54
                        reader.Close ();
 
55
                        reader.Dispose ();
 
56
                        return cmdline;
 
57
                }
 
58
                
45
59
                public static List<Application> GetApplicationList (string exec)
46
60
                {
47
61
                        exec = exec.Split (' ')[0];
54
68
                                try { pid = Convert.ToInt32 (dir.Substring (6)); } 
55
69
                                catch { continue; }
56
70
                                
57
 
                                try {
58
 
                                        reader = new StreamReader (Do.Paths.Combine ("/proc", dir, "cmdline"));
59
 
                                } catch { continue; }
60
 
                                
61
 
                                string exec_line = reader.ReadLine ();
62
 
                                reader.Close ();
63
 
                                reader.Dispose ();
 
71
                                string exec_line = CmdLineForPid (pid);
64
72
                                if (string.IsNullOrEmpty (exec_line))
65
73
                                        continue;
66
74
                                
67
75
                                if (exec_line.Contains (exec)) {
68
76
                                        foreach (Application app in GetApplications ()) {
69
77
                                                if (app.Pid == pid) {
70
 
                                                        out_app = app;
 
78
                                                        if (app.Windows.Select (win => !win.IsSkipTasklist).Any ())
 
79
                                                                out_app = app;
71
80
                                                        break;
72
81
                                                }
73
82
                                        }
120
129
                        
121
130
                        w.Activate (Gtk.Global.CurrentEventTime);
122
131
                }
 
132
                
 
133
                public static void PerformLogicalClick (IEnumerable<Application> apps)
 
134
                {
 
135
                        bool not_in_viewport = true;
 
136
                        foreach (Wnck.Application application in apps) {
 
137
                                foreach (Wnck.Window window in application.Windows) {
 
138
                                        if (!window.IsSkipTasklist && window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
139
                                                not_in_viewport = false;
 
140
                                }
 
141
                        }
 
142
                        
 
143
                        if (not_in_viewport) {
 
144
                                foreach (Wnck.Application application in apps) {
 
145
                                        foreach (Wnck.Window window in application.Windows) {
 
146
                                                if (!window.IsSkipTasklist) {
 
147
                                                        window.CenterAndFocusWindow ();
 
148
                                                        return;
 
149
                                                }
 
150
                                        }
 
151
                                }
 
152
                        }
 
153
                        
 
154
                        foreach (Wnck.Application app in apps) {
 
155
                                foreach (Wnck.Window window in app.Windows) {
 
156
                                        switch (GetClickAction (apps)) {
 
157
                                        case ClickAction.Focus:
 
158
                                                if (window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
159
                                                        window.Activate (Gtk.Global.CurrentEventTime);
 
160
                                                break;
 
161
                                        case ClickAction.Minimize:
 
162
                                                if (window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
163
                                                        window.Minimize ();
 
164
                                                break;
 
165
                                        case ClickAction.Restore:
 
166
                                                if (window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
167
                                                        window.Unminimize (Gtk.Global.CurrentEventTime);
 
168
                                                break;
 
169
                                        }
 
170
                                }
 
171
                        }
 
172
                }
 
173
                
 
174
                static ClickAction GetClickAction (IEnumerable<Application> apps)
 
175
                {
 
176
                        if (!apps.Any ())
 
177
                                return ClickAction.None;
 
178
                        
 
179
                        foreach (Wnck.Application app in apps) {
 
180
                                foreach (Wnck.Window window in app.Windows) {
 
181
                                        if (window.IsMinimized && window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
182
                                                return ClickAction.Restore;
 
183
                                }
 
184
                        }
 
185
                        
 
186
                        foreach (Wnck.Application app in apps) {
 
187
                                foreach (Wnck.Window window in app.Windows) {
 
188
                                        if (window.IsActive && window.IsInViewport (Wnck.Screen.Default.ActiveWorkspace))
 
189
                                                return ClickAction.Minimize;
 
190
                                }
 
191
                        }
 
192
                        
 
193
                        return ClickAction.Focus;
 
194
                }
123
195
        }
124
196
}