Example #1
0
        public static Tuple <ModifierKeys, Key> GetSetting(KeyBindEnum keyBind)
        {
            var keyCombo     = (string)Properties.Settings.Default[keyBind.ToString()];
            var keyStrings   = keyCombo.Split(',');
            var possibleKey  = Key.None;
            var modifierKeys = ModifierKeys.None;

            foreach (var keyString in keyStrings)
            {
                Enum.TryParse(keyString, out Key tmpKey);
                Enum.TryParse(keyString, out ModifierKeys tmpModifier);

                if (tmpKey != Key.None)
                {
                    possibleKey = tmpKey;
                }
                else if (tmpModifier != ModifierKeys.None)
                {
                    modifierKeys = modifierKeys | tmpModifier;
                }
            }

            return((possibleKey == Key.None && modifierKeys == ModifierKeys.None)
                   // Return a default for this keybind.
                ? GetDefaultKeyBind(keyBind)
                   // Or the specified one in the settings file
                : new Tuple <ModifierKeys, Key>(modifierKeys, possibleKey));
        }
Example #2
0
        private static int _GetWidth(KeyBindEnum purpose, Rectangle workingArea, Rectangle windowDimensions)
        {
            var third = workingArea.Width / 3;
            var half  = workingArea.Width / 2;

            if (purpose == KeyBindEnum.Bottom || purpose == KeyBindEnum.Mid || purpose == KeyBindEnum.Top)
            {
                if (windowDimensions.Width >= workingArea.Width)
                {
                    return(third);
                }
                if (windowDimensions.Width < half)
                {
                    return(third * 2);
                }
                return(workingArea.Width);
            }


            if (windowDimensions.Width >= third * 2)
            {
                return(third);
            }
            if (windowDimensions.Width < half)
            {
                return(half);
            }
            return(third * 2);
        }
Example #3
0
        public static void SetSetting(string value, KeyBindEnum keyBind)
        {
            var propertyToSet = KeyBindToSettingMap[keyBind];

            Properties.Settings.Default[propertyToSet] = value;
            Properties.Settings.Default.Save();
        }
Example #4
0
 private static int _GetHeight(KeyBindEnum purpose, Rectangle workingArea)
 {
     if (purpose == KeyBindEnum.Left || purpose == KeyBindEnum.Mid || purpose == KeyBindEnum.Right)
     {
         return(workingArea.Height);
     }
     return(workingArea.Height / 2);
 }
Example #5
0
 private static int _GetTop(KeyBindEnum purpose, Rectangle workingArea)
 {
     if (purpose == KeyBindEnum.BottomLeft || purpose == KeyBindEnum.Bottom || purpose == KeyBindEnum.BottomRight)
     {
         return(workingArea.Height / 2);
     }
     return(0);
 }
Example #6
0
        private static PositionDimension _GetWindowPositionPlusDimensions(KeyBindEnum purpose, Rectangle workingArea, Rectangle windowDimensions)
        {
            var positionDimension = new PositionDimension
            {
                Top    = _GetTop(purpose, workingArea),
                Height = _GetHeight(purpose, workingArea),
                // adding the workingArea.X handles multi monitors situations.
                Left  = _GetLeft(purpose, workingArea, windowDimensions) + workingArea.X,
                Width = _GetWidth(purpose, workingArea, windowDimensions)
            };

            return(positionDimension);
        }
        public KeyBindingsModel(string label, Action <KeyBindEnum> hotKeyAction, KeyBindEnum purpose)
        {
            Label         = label;
            _hotKeyAction = hotKeyAction;
            _purpose      = purpose;

            var settingsKeyBind = KeyBindSettings.GetSetting(purpose);

            if (settingsKeyBind != null && settingsKeyBind.Item2 != Key.None)
            {
                RegisterHotKey(settingsKeyBind.Item1, settingsKeyBind.Item2);
                Display = GetDisplay(settingsKeyBind.Item1, settingsKeyBind.Item2);
            }
        }
Example #8
0
        public static void MoveWindow(KeyBindEnum purpose)
        {
            IntPtr handle = GetForegroundWindow();

            if (handle == IntPtr.Zero)
            {
                // TODO: setup exception handling
                return;
            }

            Rectangle workingArea       = Screen.FromHandle(handle).WorkingArea;
            var       windowDimension   = _GetActiveWindowDimensions(handle);
            var       positionDimension = _GetWindowPositionPlusDimensions(purpose, workingArea, windowDimension);

            SetWindowPos(handle, 0,
                         positionDimension.Left - 7,
                         positionDimension.Top,
                         positionDimension.Width + 14,
                         positionDimension.Height + 7,
                         SWP.SHOWWINDOW);
        }
Example #9
0
        private static Tuple <ModifierKeys, Key> GetDefaultKeyBind(KeyBindEnum keyBind)
        {
            var key = DefaultKeyBindings[keyBind];

            return(new Tuple <ModifierKeys, Key>(ModifierKeys.Control | ModifierKeys.Alt, key));
        }
Example #10
0
 public void MoveWindowOnHotKeyPressed(KeyBindEnum purpose)
 {
     MoveActiveWindow.MoveWindow(purpose);
 }
Example #11
0
 public void ToggleWindowMonitorOnHotKeyPressed(KeyBindEnum purpose)
 {
     MoveActiveWindow.ToggleWindowMonitor();
 }