private static void setupWindowRules() { if (!settings.sections.Contains("Window Rules")) { return; } foreach (List<string> list in settings.KeysUnderSection("Window Rules")) { string winClass = list[1]; string winTitle = list[2]; long winStyle = long.Parse(list[3], NumberStyles.HexNumber); string winRule = list[4]; bool negative = false; if (winClass.StartsWith("!")) { negative = true; winClass = winClass.Substring(1); } int value = Convert.ToInt32(settings.ReadSetting(list.ToArray())); WindowRules rule; if (WindowRules.TryParse(winRule, true, out rule)) { WindowRule newRule = new WindowRule(rule, value); WindowMatch newMatch = new WindowMatch(winClass, winTitle, winStyle, negative); windowRules[newMatch] = newRule; } } }
private static void pollWindows_Tick(object sender, EventArgs e) { _globalHook.unhook(); _globalHook.hook(); if (Win32API.GetForegroundWindow() != focusTrack) { focusTrack = Win32API.GetForegroundWindow(); OnWindowFocusChange(GetWindowObjectByHandle(focusTrack), new WindowEventArgs(Manager.GetFocussedMonitor().Screen)); } Windows windows = new Windows(); List<Window> allCurrentlyVisibleWindows = new List<Window>(); List<Window> hiddenNotShownByMeWindows = new List<Window>(); foreach (Window window in windows) { bool windowIgnored = false; if ((from win in hiddenWindows select win.handle).Contains(window.handle)) { hiddenNotShownByMeWindows.Add(window); } if (!_handles.Contains(window.handle)) { Manager.Log("Found a new window! {0} isn't in the main listing".With(window.Title)); foreach (KeyValuePair<WindowMatch, WindowRule> kvPair in new Dictionary<WindowMatch, WindowRule>(windowRules)) { if (kvPair.Key.windowMatches(window)) { WindowRule rule = kvPair.Value; if (rule.rule == WindowRules.ignore) { windowIgnored = rule.data == 1; } if (rule.rule == WindowRules.noResize) { window.AllowResize = rule.data != 1; } if (rule.rule == WindowRules.stripBorders) { window.ShowCaption = rule.data != 1; WindowMatch newMatch = new WindowMatch(window.ClassName, kvPair.Key.Title, kvPair.Key.Style); WindowRule newRule = new WindowRule(WindowRules.ignore, 0); windowRules.Add(newMatch, newRule); } if (rule.rule == WindowRules.tilingStyle) { window.TilingType = (WindowTilingType) rule.data; } if (rule.rule == WindowRules.topmost) { window.TopMost = rule.data != 0; } } } if (windowIgnored) { continue; } _windowList.Add(window); _handles.Add(window.handle); OnWindowCreate(window, new WindowEventArgs(window.Screen)); } allCurrentlyVisibleWindows.Add(window); } foreach (Window window in hiddenNotShownByMeWindows) { window.Activate(); Window window1 = window; var screensWithWindow = (from screen in (from monitor in monitors select monitor.screens).SelectMany(x=>x) where screen.windows.Contains(window1) select screen); TagScreen firstScreenWithWindow = screensWithWindow.First(); firstScreenWithWindow.parent.Bar.BarWindow.Activate(); SendMessage(Message.Screen, Level.Monitor, firstScreenWithWindow.tag); window.Activate(); } if (hiddenNotShownByMeWindows.Count > 0) { return; } foreach (Window window in new List<Window>(_windowList)) { if (!allCurrentlyVisibleWindows.Contains(window)) { Manager.Log("{0} is no longer open".With(window.Title), 1); if (!hiddenWindows.Contains(window)) { Manager.Log("{0} is also not hidden - it's closed".With(window.Title)); _windowList.Remove(window); _handles.Remove(window.handle); //Screen windowScreen = Screen.FromHandle(window.handle); OnWindowDestroy(window, new WindowEventArgs(window.Screen)); } else { Manager.Log("{0} is just hidden, not closed".With(window.Title), 1); } } } foreach (Monitor monitor in monitors) { monitor.GetActiveScreen().AssertLayout(); } }