Пример #1
0
        private void HotKeyPressed(short id, IntPtr currentWindowHandle)
        {
            HotKeyFunction functionCalled = Runtime.Instance.Settings.HotKeys.GetFunction(id);

            Runtime.Instance.WriteDebug(nameof(HotKeyPressed), nameof(functionCalled), functionCalled, "HotKeys");
            switch (functionCalled)
            {
            case HotKeyFunction.HideCurrentWindow:
                if (!currentWindowHandle.Equals(IntPtr.Zero))
                {
                    WindowInfo.Find(currentWindowHandle).Hide();
                }
                break;

            case HotKeyFunction.UnhideAllWindows:
                this.UnhideAllWindows(this, new EventArgs());
                break;

            case HotKeyFunction.ToggleLastWindow:
                WindowInfo.Last?.ToggleHidden();
                break;

            case HotKeyFunction.UnhideLastWindow:
                Runtime.Instance.WindowManager.GetLastWindow()?.Show();
                break;

            default:
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowsStoreItem"/> class.
        /// </summary>
        public WindowsStoreItem()
        {
            if (this.Handle == IntPtr.Zero)
            {
                return;
            }

            WindowInfo window = WindowInfo.Find(this.Handle);
        }
Пример #3
0
        public void Add(WindowsStoreItem item)
        {
            item.RegisterHandlers(WindowInfo.Find(item.Handle));
            if (this.items.Contains(item))
            {
                return;
            }

            this.items.Add(item);
        }
Пример #4
0
        void IList <WindowsStoreItem> .RemoveAt(int index)
        {
            IntPtr handle = this.items[index].Handle;

            this.items.RemoveAt(index);
            if (this.Removed != null)
            {
                this.Removed(this, new WindowInfoEventArgs(WindowInfo.Find(handle)));
            }
        }
Пример #5
0
 internal static bool TryFind(WindowsStoreItem storeItem, out WindowInfo windowInfo)
 {
     windowInfo = null;
     if (storeItem != null)
     {
         windowInfo = WindowInfo.Find(storeItem.Handle);
         windowInfo.OriginalState = storeItem.LastState;
         windowInfo.isPinned      = storeItem.IsPinned;
     }
     return(windowInfo != null && windowInfo.IsValid);
 }
        internal static WindowInfo GetForegroundWindow()
        {
            IntPtr hWnd = NativeMethods.GetForegroundWindowHandle();

            if (hWnd == IntPtr.Zero)
            {
                return(null);
            }

            return(WindowInfo.Find(hWnd));
        }
Пример #7
0
        private void RemoveClosedApplication(object sender, WindowInfoEventArgs e)
        {
            this.Invoke(() =>
            {
                string key = e.Handle.ToInt64().ToString();
                if (!this.hiddenWindows.Items.ContainsKey(key))
                {
                    return;
                }

                WindowInfo.Find(e.Handle).ApplicationExited -= this.RemoveClosedApplication;
                this.hiddenWindows.Items.RemoveByKey(key);
            });
        }
Пример #8
0
        void ICollection <WindowsStoreItem> .Clear()
        {
            long[] handleVals = this.items.Select(item => item.HandleValue).ToArray();
            this.items.Clear();
            if (this.Removed == null)
            {
                return;
            }

            foreach (long value in handleVals)
            {
                IntPtr handle = new IntPtr(value);
                this.Removed(this, new WindowInfoEventArgs(WindowInfo.Find(handle)));
            }
        }
Пример #9
0
        public bool Remove(IntPtr handle)
        {
            long             value = handle.ToInt64();
            WindowsStoreItem match = this.items.FirstOrDefault(item => item.Handle == handle);

            if (match == null)
            {
                return(false);
            }
            if (this.items.Remove(match))
            {
                this.Removed?.Invoke(this, new WindowInfoEventArgs(WindowInfo.Find(handle)));
                return(true);
            }
            return(false);
        }
Пример #10
0
        public WindowsStoreItem Add(IntPtr handle)
        {
            WindowsStoreItem returnValue = null;
            long             value       = handle.ToInt64();

            if (this.items.Any(item => item.Handle == handle))
            {
                returnValue = this.items.FirstOrDefault(item => item.Handle == handle);
                WindowInfo window = WindowInfo.Find(handle);
            }
            else
            {
                WindowInfo window = WindowInfo.Find(handle);
                returnValue = new WindowsStoreItem(window);
                this.items.Add(returnValue);
                this.Added?.Invoke(this, new WindowInfoEventArgs(window));
            }
            returnValue?.RegisterHandlers();

            return(returnValue);
        }
Пример #11
0
        public void RegisterHandlers(WindowInfo window = null)
        {
            if (window == null)
            {
                window = WindowInfo.Find(this.Handle);
            }

            if (!Runtime.Instance.WindowManager.Exists(window) ||
                this.handlersRegistered)
            {
                return;
            }

            window.OriginalState    = this.LastState;
            window.IsPinned         = this.IsPinned;
            window.Hidden          += (s, e) => { this.State |= WindowStates.Hidden; };
            window.Shown           += (s, e) => { this.State &= ~WindowStates.Hidden; };
            window.Pinned          += (s, e) => { this.State |= WindowStates.Pinned; };
            window.Unpinned        += (s, e) => { this.State &= ~WindowStates.Pinned; };
            window.Locked          += (s, e) => { this.State |= WindowStates.Protected; };
            window.Unlocked        += (s, e) => { this.State &= ~WindowStates.Protected; };
            this.StateChanged      += (s, e) => { HiddenWindowStore.Save(Runtime.Instance.Store); };
            this.handlersRegistered = true;
        }