예제 #1
0
파일: Window.cs 프로젝트: Phoshi/TWiME
 public void CatchMessage(HotkeyMessage message)
 {
     if (message.Message == Message.Close) {
         this.Close();
     }
     else if (message.Message == Message.TilingType) {
         if (message.data > 0) {
             TilingType = (WindowTilingType) message.data;
         }
         else if (message.data == -1) {
             int currentType = (int) TilingType;
             currentType++;
             if (currentType >= Enum.GetValues(typeof(WindowTilingType)).Length) {
                 currentType = 0;
             }
             TilingType = (WindowTilingType) currentType;
         }
         else {
             TilingType = TilingType == WindowTilingType.Normal ? WindowTilingType.FullScreen : WindowTilingType.Normal;
         }
     }
     else if (message.Message == Message.TopMost) {
         if (message.data > 0) {
             TopMost = message.data != 0;
         }
         else {
             TopMost = !TopMost;
         }
     }
     else if (message.Message == Message.WindowChrome) {
         if (message.data > 0) {
             ShowCaption = message.data != 0;
         }
         else {
             ShowCaption = !ShowCaption;
         }
     }
 }
예제 #2
0
파일: Manager.cs 프로젝트: Phoshi/TWiME
 private static void CatchMessage(HotkeyMessage message)
 {
     if (message.Message == Message.Close) {
         Manager.Log("Beginning shutdown loop", 10);
         foreach (Window window in _windowList) {
             Manager.Log("Setting {0} visible and not maximised".With(window), 10);
             window.Visible = true;
             window.Maximised = false;
             window.ShowCaption = true;
         }
         Manager.Log("Showing taskbar", 10);
         Taskbar.Hidden = false;
         if (message.data == 0) {
             Application.Exit();
         }
         else {
             Application.Restart();
         }
     }
     if (message.Message == Message.Switch) {
         Manager.Log("Toggling taskbar");
         Taskbar.Hidden = !Taskbar.Hidden;
         Manager.monitors[0].AssertTagLayout();
     }
 }
예제 #3
0
파일: TagScreen.cs 프로젝트: Phoshi/TWiME
 public void CatchMessage(HotkeyMessage message)
 {
     if (message.level == Level.Screen) {
         if (message.Message == Message.Focus) {
             if (_windowList.Count == 0) {
                 return;
             }
             if (Screen.FromHandle(message.handle).DeviceName == _parent.Name) {
                 int newIndex = GetFocusedWindowIndex() + message.data;
                 if (newIndex >= _windowList.Count) {
                     newIndex = 0;
                 }
                 else if (newIndex < 0) {
                     newIndex = _windowList.Count - 1;
                 }
                 Console.WriteLine(newIndex);
                 _windowList[newIndex].Activate();
                 Manager.CenterMouseOnActiveWindow();
             }
         }
         if (message.Message == Message.Switch) {
             if (_windowList.Count == 0) {
                 return;
             }
             if (Screen.FromHandle(message.handle).DeviceName == _parent.Name) {
                 int oldIndex = GetFocusedWindowIndex();
                 int newIndex = oldIndex + message.data;
                 if (newIndex >= _windowList.Count) {
                     newIndex = 0;
                 }
                 else if (newIndex < 0) {
                     newIndex = _windowList.Count - 1;
                 }
                 if (oldIndex >= 0) {
                     Window oldWindow = _windowList[oldIndex];
                     Window newWindow = _windowList[newIndex];
                     _windowList[oldIndex] = newWindow;
                     _windowList[newIndex] = oldWindow;
                     AssertLayout();
                     Manager.CenterMouseOnActiveWindow();
                 }
             }
         }
         if (message.Message == Message.SwitchThis) {
             int oldIndex = GetFocusedWindowIndex();
             if (oldIndex == -1) {
                 oldIndex = 0;
             }
             int newIndex = message.data;
             Window newWindow, oldWindow;
             try {
                 oldWindow = _windowList[oldIndex];
                 newWindow = _windowList[newIndex];
             }
             catch (ArgumentOutOfRangeException) {
                 return;
             }
             _windowList[oldIndex] = newWindow;
             _windowList[newIndex] = oldWindow;
             AssertLayout();
             Manager.CenterMouseOnActiveWindow();
         }
         if (message.Message == Message.FocusThis) {
             if (message.data < _windowList.Count) {
                 _windowList[message.data].Activate();
                 Manager.CenterMouseOnActiveWindow();
             }
         }
         if (message.Message == Message.Monitor) {
             int newMonitorIndex = Manager.GetFocussedMonitorIndex() + message.data;
             if (newMonitorIndex < 0) {
                 newMonitorIndex = Manager.monitors.Count - 1;
             }
             else if (newMonitorIndex >= Manager.monitors.Count) {
                 newMonitorIndex = 0;
             }
             Monitor newMonitor = Manager.monitors[newMonitorIndex];
             Window focussedWindow = GetFocusedWindow();
             newMonitor.CatchWindow(this.ThrowWindow(focussedWindow));
             _parent.screens.Where(screen => screen.windows.Contains(focussedWindow)).ToList().ForEach(screen => screen._windowList.Remove(focussedWindow));
             AssertLayout();
             newMonitor.GetActiveScreen().Enable();
             Manager.CenterMouseOnActiveWindow();
         }
         if (message.Message == Message.MonitorMoveThis) {
             Manager.monitors[message.data].CatchWindow(ThrowWindow(GetFocusedWindow()));
             AssertLayout();
             Manager.monitors[message.data].GetActiveScreen().Activate();
             Manager.CenterMouseOnActiveWindow();
         }
         if (message.Message == Message.Splitter) {
             layout.MoveSplitter(message.data / 100.0f);
             Manager.settings.AddSetting(layout.GetSplitter(), parent.SafeName,
                                         (_tag).ToString(), "Splitter");
         }
         if (message.Message == Message.VSplitter) {
             layout.MoveSplitter(message.data / 100.0f, true);
             Manager.settings.AddSetting(layout.GetSplitter(true), parent.SafeName,
                                         (_tag).ToString(), "VSplitter");
         }
         if (message.Message == Message.Close) {
             foreach (Window window in _windowList) {
                 window.Visible = true;
                 window.Maximised = false;
             }
         }
         if (message.Message == Message.Close) {
             _windowList[message.data].Close();
         }
     }
     else {
         GetFocusedWindow().CatchMessage(message);
         AssertLayout();
     }
 }
예제 #4
0
파일: Manager.cs 프로젝트: Phoshi/TWiME
 public static void SendMessage(Message type, Level level, int data)
 {
     IntPtr focussed = Win32API.GetForegroundWindow();
     HotkeyMessage message = new HotkeyMessage(type, level, focussed, data);
     if (message.level == Level.Global) {
         CatchMessage(message);
     }
     else {
         GetFocussedMonitor().CatchMessage(message);
     }
 }
예제 #5
0
파일: Monitor.cs 프로젝트: Phoshi/TWiME
        public void CatchMessage(HotkeyMessage message)
        {
            if (message.level == Level.Monitor) {
                if (message.Message == Message.MonitorSwitch) {
                    int newIndex = Manager.GetFocussedMonitorIndex() + message.data;
                    if (newIndex < 0) {
                        newIndex = Manager.monitors.Count - 1;
                    }
                    if (newIndex >= Manager.monitors.Count) {
                        newIndex = 0;
                    }
                    Manager.monitors[newIndex].activate();
                    Manager.monitors[newIndex].Bar.Redraw();
                    Manager.CenterMouseOnActiveWindow();
                }
                if (message.Message == Message.MonitorFocus) {
                    Manager.monitors[message.data].activate();
                    Manager.CenterMouseOnActiveWindow();
                }
                if (message.Message == Message.Screen) {
                    if (!IsTagEnabled(message.data)) {
                        if (message.data < 0) {
                            message.data = _lastFocussedTagScreen;
                        }
                        _lastFocussedTagScreen = GetEnabledTags().First();
                        SetTagState(message.data, !IsTagEnabled(message.data));
                        Manager.CenterMouseOnActiveWindow();
                    }
                    else if (GetActiveTag() != message.data) {
                        _activeTag = message.data;
                        GetActiveScreen().Activate();
                    }
                    else {
                        SetTagState(message.data, true, false);
                    }
                }
                if (message.Message == Message.ScreenRelative) {
                    int newIndex;
                    if (GetEnabledTags().Count <= 1) {
                        newIndex = GetActiveTag() + message.data;
                    }
                    else {
                        List<int> enabledTags = GetEnabledTags();
                        enabledTags.Sort();
                        int newIndexPosition = enabledTags.IndexOf(GetActiveTag()) + message.data;
                        if (newIndexPosition <= GetEnabledTags().Count-1 && newIndexPosition >= 0) {
                            newIndex = enabledTags[newIndexPosition];
                        }
                        else if (newIndexPosition == 0) {
                            newIndex = enabledTags.Last();
                        }
                        else {
                            newIndex = enabledTags.First();
                        }
                    }
                    if (newIndex < 0) {
                        newIndex = tagScreens.Count() - 1;
                    }
                    else if (newIndex >= tagScreens.Count()) {
                        newIndex = 0;
                    }
                    CatchMessage(new HotkeyMessage(Message.Screen, Level.Monitor, message.handle, newIndex));
                }
                if (message.Message == Message.TagWindow) {
                    if (GetActiveScreen().GetFocusedWindow().Equals(Bar.BarWindow)) {
                        return;
                    }
                    if (message.data >= tagScreens.Count()) {
                        ChangeNumberOfTagScreens(message.data + 1);
                    }
                    if (tagScreens[message.data].windows.Contains(GetActiveScreen().GetFocusedWindow())) {
                        Window focussedWindow = GetActiveScreen().GetFocusedWindow();
                        int numTags =(from screen in tagScreens select screen.windows).SelectMany(window => window).Where(
                            window => window == focussedWindow).Count();
                        if (numTags == 1) {
                            return;
                        }
                        tagScreens[message.data].ThrowWindow(focussedWindow);
                        focussedWindow.Visible = false;
                        if (IsTagEnabled(message.data)) {
                            GetActiveScreen().Enable();
                        }
                    }
                    else {
                        tagScreens[message.data].CatchWindow(GetActiveScreen().GetFocusedWindow());
                    }
                    GetActiveScreen().AssertLayout();
                    Manager.CenterMouseOnActiveWindow();
                }
                if (message.Message == Message.SwapTagWindow) {
                    if (GetActiveScreen().GetFocusedWindow().Equals(Bar.BarWindow)) {
                        return;
                    }
                    if (message.data == GetActiveScreen().tag) {
                        return;
                    }
                    Window thrown = GetActiveScreen().ThrowWindow(GetActiveScreen().GetFocusedWindow());
                    GetActiveScreen().AssertLayout();
                    tagScreens[message.data].CatchWindow(thrown);
                    if (!IsTagEnabled(message.data)) {
                        thrown.Visible = false;
                    }
                    Manager.CenterMouseOnActiveWindow();
                }
                if (message.Message == Message.SwapTagWindowRelative) {
                    if (GetActiveScreen().GetFocusedWindow().Equals(Bar.BarWindow)) {
                        return;
                    }
                    int newIndex;

                    if (GetEnabledTags().Count == 1) {
                        newIndex = GetActiveScreen().tag + message.data;
                    }
                    else {
                        List<int> enabledTags = GetEnabledTags();
                        enabledTags.Sort();
                        int newIndexPosition = enabledTags.IndexOf(GetActiveTag()) + message.data;
                        if (newIndexPosition <= GetEnabledTags().Count - 1 && newIndexPosition >= 0) {
                            newIndex = enabledTags[newIndexPosition];
                        }
                        else if (newIndexPosition == 0) {
                            newIndex = enabledTags.Last();
                        }
                        else {
                            newIndex = enabledTags.First();
                        }
                    }
                    if (newIndex < 0) {
                        newIndex = tagScreens.Count() - 1;
                    }
                    else if (newIndex >= tagScreens.Count()) {
                        newIndex = 0;
                    }
                    CatchMessage(new HotkeyMessage(Message.SwapTagWindow, Level.Monitor, message.handle, newIndex));
                    CatchMessage(new HotkeyMessage(Message.Screen, Level.Monitor, message.handle, newIndex));
                }
                if (message.Message == Message.Layout) {
                    int newIndex = message.data;
                    if (newIndex < Manager.layouts.Count) {
                        TagScreen switchScreen = this.GetActiveScreen();
                        switchScreen.activeLayout = newIndex;
                        switchScreen.InitLayout();
                        if (IsTagEnabled(switchScreen.tag)) {
                            switchScreen.AssertLayout();
                            Manager.CenterMouseOnActiveWindow();
                        }
                    }
                }
                if (message.Message == Message.LayoutRelative) {
                    TagScreen switchScreen = tagScreens[message.data];
                    int newIndex = switchScreen.activeLayout + 1;
                    if (newIndex < 0) {
                        newIndex = Manager.layouts.Count() - 1;
                    }
                    else if (newIndex >= Manager.layouts.Count) {
                        newIndex = 0;
                    }
                    switchScreen.activeLayout = newIndex;
                    switchScreen.InitLayout();
                    if (IsTagEnabled(switchScreen.tag)) {
                        switchScreen.AssertLayout();
                        Manager.CenterMouseOnActiveWindow();
                    }
                }
                if (message.Message == Message.LayoutRelativeReverse) {
                    TagScreen switchScreen = tagScreens[message.data];
                    int newIndex = switchScreen.activeLayout - 1;
                    if (newIndex < 0) {
                        newIndex = Manager.layouts.Count() - 1;
                    }
                    else if (newIndex >= Manager.layouts.Count) {
                        newIndex = 0;
                    }
                    switchScreen.activeLayout = newIndex;
                    switchScreen.InitLayout();
                    if (IsTagEnabled(switchScreen.tag)) {
                        switchScreen.AssertLayout();
                        Manager.CenterMouseOnActiveWindow();
                    }
                }
                if (message.Message == Message.Split) {
                    var inactiveTags = GetDisabledTags();
                    if (inactiveTags.Count > 0) {
                        SetTagState((from tag in inactiveTags orderby tagScreens[tag].windows.Count() > 0 descending select tag).First(), true, false);
                    }
                }
                if (message.Message == Message.OnlyShow) {
                    foreach (int enabledTag in new List<int>(GetEnabledTags())) {
                        if (enabledTag != GetActiveTag()) {
                            SetTagState(enabledTag, false, true, true);
                        }
                    }
                    reorganiseActiveTagSpaces();
                }
                if (message.Message == Message.Hide) {
                    int activeTag = GetActiveTag();
                    if (GetEnabledTags().Count == 2) {
                        TagScreen newActiveScreen = GetEnabledScreens().First(screen=>screen.tag!=activeTag);
                        _activeTag = newActiveScreen.tag;
                        Manager.SendMessage(Message.OnlyShow, Level.Monitor, 0);
                        return;
                    }
                    SetTagState(activeTag, false);
                }
                if (message.Message == Message.ShowAll) {
                    foreach (TagScreen tagScreen in tagScreens) {
                        if (tagScreen.windows.Count > 0) {
                            SetTagState(tagScreen.tag, true, false, true);
                        }
                    }
                    reorganiseActiveTagSpaces();
                }
                if (message.Message == Message.Splitter) {
                    _splitter += message.data / 100.0f;
                    Manager.settings.AddSetting(_splitter, Screen.DeviceName.Replace(".", ""), "Splitter");
                    reorganiseActiveTagSpaces();
                }
                if (message.Message == Message.SplitRotate) {
                    if (message.data > 0) {
                        int poppedTag = _enabledTags.ElementAt(0);
                        _enabledTags.RemoveAt(0);
                        _enabledTags.Add(poppedTag);
                    }
                    else {
                        int poppedTag = _enabledTags.Last();
                        _enabledTags.RemoveAt(_enabledTags.Count - 1);
                        _enabledTags.Insert(0, poppedTag);
                    }
                    reorganiseActiveTagSpaces();
                }
                if (message.Message == Message.ReindexTagScreens) {
                    int newNumber = tagScreens.Length + message.data;
                    ChangeNumberOfTagScreens(newNumber);
                }
            }
            else {
                GetActiveScreen().CatchMessage(message);
            }
            Bar.Redraw();
        }