Ejemplo n.º 1
0
        private void getInitialWindows()
        {
            EnumWindows((hwnd, lParam) =>
            {
                ApplicationWindow win = new ApplicationWindow(hwnd);

                // set window category if provided by shell
                win.Category = TaskCategoryProvider?.GetCategory(win);

                if (win.CanAddToTaskbar && win.ShowInTaskbar && !Windows.Contains(win))
                {
                    Windows.Add(win);
                }

                return(true);
            }, 0);

            IntPtr hWndForeground = GetForegroundWindow();

            if (Windows.Any(i => i.Handle == hWndForeground && i.ShowInTaskbar))
            {
                ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWndForeground);
                win.State = ApplicationWindow.WindowState.Active;
                win.SetShowInTaskbar();
            }
        }
Ejemplo n.º 2
0
        private void getInitialWindows()
        {
            EnumWindows((hwnd, lParam) =>
            {
                ApplicationWindow win = new ApplicationWindow(this, hwnd);

                if (win.CanAddToTaskbar && win.ShowInTaskbar && !Windows.Contains(win))
                {
                    Windows.Add(win);

                    sendTaskbarButtonCreatedMessage(win.Handle);
                }

                return(true);
            }, 0);

            IntPtr hWndForeground = GetForegroundWindow();

            if (Windows.Any(i => i.Handle == hWndForeground && i.ShowInTaskbar))
            {
                ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWndForeground);
                win.State = ApplicationWindow.WindowState.Active;
                win.SetShowInTaskbar();
            }
        }
Ejemplo n.º 3
0
        public void Update(WindowUpdate windowUpdate)
        {
            if (_isDisposed)
            {
                return;
            }

            lock (_listLock)
            {
                foreach (var windowInformation in windowUpdate.UpdatedWindows)
                {
                    Windows.FirstOrDefault(x => x.Handle == windowInformation.Handle)?.UpdateData(windowInformation);
                }

                foreach (var windowInformation in windowUpdate.NewWindows)
                {
                    if (Windows.All(x => x.Handle != windowInformation.Handle))
                    {
                        Windows.Add(new WindowRenderInfo(windowInformation));
                    }
                }

                foreach (var windowToRemove in Windows.Where(x => !windowUpdate.AllWindows.Contains(x.Handle)).ToList()) //ToList is important to allow removing from the list
                {
                    Windows.Remove(windowToRemove);
                }

                Windows =
                    new List <WindowRenderInfo>(windowUpdate.AllWindows.Where(
                                                    x => Windows.Any(y => y.Handle == x))
                                                .Select(x => Windows.FirstOrDefault(y => y.Handle == x)));

                /*var windowsIndex = 0;
                 * for (int i = 0; i < windowUpdate.AllWindows.Count; i++)
                 * {
                 *  var windowHandle = windowUpdate.AllWindows[i];
                 *  var existingWindow = Windows.FirstOrDefault(x => x.Handle == windowHandle);
                 *  if (existingWindow == null)
                 #if DEBUG
                 *      throw new Exception("Window does not exist");
                 #else
                 *      continue;
                 #endif
                 *
                 *  Windows.Move(Windows.IndexOf(existingWindow), windowsIndex);
                 *  windowsIndex++;
                 * }*/

                if (windowUpdate.RenderedWindow != null)
                {
                    var windowToUpdate = Windows.FirstOrDefault(x => x.Handle == windowUpdate.RenderedWindowHandle);
                    windowToUpdate?.UpdateImage(windowUpdate.RenderedWindow);
                }
            }

            _updateReceivedAutoResetEvent.Set();
        }
Ejemplo n.º 4
0
        public void AddWindow()
        {
            Windows.Add(new Entities.Window(new Rect(tiles.First())));

            if (Windows.Any(w => w.Selected) == false)
            {
                Windows.First().Selected = true;
            }
        }
Ejemplo n.º 5
0
 private void UncloakEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
 {
     if (hWnd != IntPtr.Zero && idObject == 0 && idChild == 0)
     {
         if (Windows.Any(i => i.Handle == hWnd))
         {
             ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWnd);
             win.Uncloak();
         }
     }
 }
Ejemplo n.º 6
0
 private void removeWindow(IntPtr hWnd)
 {
     if (Windows.Any(i => i.Handle == hWnd))
     {
         do
         {
             ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWnd);
             win.Dispose();
             Windows.Remove(win);
         }while (Windows.Any(i => i.Handle == hWnd));
     }
 }
Ejemplo n.º 7
0
        public void RemoveWindow()
        {
            var selected = Windows.FirstOrDefault(w => w.Selected);

            if (selected != null)
            {
                Windows.Remove(selected);
                if (Windows.Any())
                {
                    Windows.Last().Selected = true;
                }
            }
        }
Ejemplo n.º 8
0
        void SetState()
        {
            ItemState state = 0;

            if (Windows.Any(w => w == Wnck.Screen.Default.ActiveWindow))
            {
                state |= ItemState.Active;
            }
            if (ManagedWindows.Any(w => w.NeedsAttention()))
            {
                state |= ItemState.Urgent;
            }

            State = state;
        }
Ejemplo n.º 9
0
        protected override ClickAnimation OnClicked(uint button, ModifierType mod, double xPercent, double yPercent)
        {
            if (!ManagedWindows.Any() || button != 1)
            {
                return(ClickAnimation.None);
            }

            List <Wnck.Window>        stack   = new List <Wnck.Window> (Wnck.Screen.Default.WindowsStacked);
            IEnumerable <Wnck.Window> windows = ManagedWindows.OrderByDescending(w => stack.IndexOf(w));

            bool not_in_viewport = !windows.Any(w => !w.IsSkipTasklist && w.IsInViewport(w.Screen.ActiveWorkspace));
            bool urgent          = windows.Any(w => w.NeedsAttention());

            if (not_in_viewport || urgent)
            {
                foreach (Wnck.Window window in windows)
                {
                    if (urgent && !window.NeedsAttention())
                    {
                        continue;
                    }

                    if (!window.IsSkipTasklist)
                    {
                        WindowControl.IntelligentFocusOffViewportWindow(window, windows);
                        return(ClickAnimation.Darken);
                    }
                }
            }

            if (windows.Any(w => w.IsMinimized && w.IsInViewport(Wnck.Screen.Default.ActiveWorkspace)))
            {
                WindowControl.RestoreWindows(windows);
            }
            else if (windows.Any(w => w.IsActive && w.IsInViewport(Wnck.Screen.Default.ActiveWorkspace)) ||
                     Windows.Any(w => w == Wnck.Screen.Default.ActiveWindow))
            {
                WindowControl.MinimizeWindows(windows);
            }
            else
            {
                WindowControl.FocusWindows(windows);
            }

            return(ClickAnimation.Darken);
        }
Ejemplo n.º 10
0
        private void UpdateImages()
        {
            bool hasWindows = Windows.Any();

            IsActive = hasWindows;
            if (hasWindows)
            {
                Win32Window window = Windows.First();
                Text = string.IsNullOrEmpty(window.Title) ? System.IO.Path.GetFileName(window.FileName) : window.Title;
                Text = StringUtils.LimitCharacters(Text, 40, 50);
                var bitmap = IconManager.GetIcon(window.FileName, VMLocator.Main.IconSize) ?? IconManager.UnknownIcon;
                Icon         = bitmap;
                BlurredIcon  = BitmapEffectHelper.GaussianBlur(bitmap, 2.5f);
                ChildIcon    = IconManager.GetAppIcon(window.Hwnd);
                HasChildIcon = WindowManager.Manager.Windows.Count(w => w.FileName == window.FileName) > 1;
            }
            if (Pinned && string.IsNullOrEmpty(ImagePath))
            {
                var bitmap = IconManager.GetIcon(Path, VMLocator.Main.IconSize) ?? IconManager.UnknownIcon;
                Icon        = bitmap;
                BlurredIcon = BitmapEffectHelper.GaussianBlur(bitmap, 2.5f);
            }
        }
Ejemplo n.º 11
0
        public void RefreshList(CheckedListBox list)
        {
            Windows = WindowsLogic.GetNonExplorerWindows();

            foreach (Window window in Windows)
            {
                if (!list.Items.Contains(window.ProcessName))
                {
                    list.Items.Add(window.ProcessName);
                }
            }

            int itemsCount = list.Items.Count - 1;

            for (int i = itemsCount; i > 0; i--)
            {
                if (!Windows.Any(x => x.ProcessName == (string)list.Items[i]))
                {
                    list.Items.Remove(list.Items[i]);
                }
            }

            list.Refresh();
        }
Ejemplo n.º 12
0
        private void ShellWinProc(Message msg)
        {
            if (msg.Msg == WM_SHELLHOOKMESSAGE)
            {
                try
                {
                    lock (_windowsLock)
                    {
                        switch ((HSHELL)msg.WParam.ToInt32())
                        {
                        case HSHELL.WINDOWCREATED:
                            CairoLogger.Instance.Debug("Created: " + msg.LParam.ToString());
                            if (!Windows.Any(i => i.Handle == msg.LParam))
                            {
                                addWindow(msg.LParam);
                            }
                            else
                            {
                                ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
                                win.UpdateProperties();
                            }
                            break;

                        case HSHELL.WINDOWDESTROYED:
                            CairoLogger.Instance.Debug("Destroyed: " + msg.LParam.ToString());
                            removeWindow(msg.LParam);
                            break;

                        case HSHELL.WINDOWREPLACING:
                            CairoLogger.Instance.Debug("Replacing: " + msg.LParam.ToString());
                            if (Windows.Any(i => i.Handle == msg.LParam))
                            {
                                ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
                                win.State = ApplicationWindow.WindowState.Inactive;
                                win.SetShowInTaskbar();
                            }
                            else
                            {
                                addWindow(msg.LParam);
                            }
                            break;

                        case HSHELL.WINDOWREPLACED:
                            CairoLogger.Instance.Debug("Replaced: " + msg.LParam.ToString());
                            removeWindow(msg.LParam);
                            break;

                        case HSHELL.WINDOWACTIVATED:
                        case HSHELL.RUDEAPPACTIVATED:
                            CairoLogger.Instance.Debug("Activated: " + msg.LParam.ToString());

                            foreach (var aWin in Windows.Where(w => w.State == ApplicationWindow.WindowState.Active))
                            {
                                aWin.State = ApplicationWindow.WindowState.Inactive;
                            }

                            if (msg.LParam != IntPtr.Zero)
                            {
                                ApplicationWindow win = null;

                                if (Windows.Any(i => i.Handle == msg.LParam))
                                {
                                    win       = Windows.First(wnd => wnd.Handle == msg.LParam);
                                    win.State = ApplicationWindow.WindowState.Active;
                                    win.SetShowInTaskbar();
                                }
                                else
                                {
                                    win = addWindow(msg.LParam, ApplicationWindow.WindowState.Active);
                                }

                                if (win != null)
                                {
                                    foreach (ApplicationWindow wind in Windows)
                                    {
                                        if (wind.WinFileName == win.WinFileName)
                                        {
                                            wind.SetShowInTaskbar();
                                        }
                                    }
                                }
                            }
                            break;

                        case HSHELL.FLASH:
                            CairoLogger.Instance.Debug("Flashing window: " + msg.LParam.ToString());
                            if (Windows.Any(i => i.Handle == msg.LParam))
                            {
                                ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
                                win.State = ApplicationWindow.WindowState.Flashing;
                            }
                            else
                            {
                                addWindow(msg.LParam, ApplicationWindow.WindowState.Flashing, true);
                            }
                            break;

                        case HSHELL.ACTIVATESHELLWINDOW:
                            CairoLogger.Instance.Debug("Activate shell window called.");
                            break;

                        case HSHELL.ENDTASK:
                            CairoLogger.Instance.Debug("EndTask called: " + msg.LParam.ToString());
                            removeWindow(msg.LParam);
                            break;

                        case HSHELL.GETMINRECT:
                            CairoLogger.Instance.Debug("GetMinRect called: " + msg.LParam.ToString());
                            SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(SHELLHOOKINFO));
                            winHandle.rc = new Interop.NativeMethods.Rect {
                                Bottom = 100, Left = 0, Right = 100, Top = 0
                            };
                            Marshal.StructureToPtr(winHandle, msg.LParam, true);
                            msg.Result = winHandle.hwnd;
                            return;     // return here so the result isnt reset to DefWindowProc

                        case HSHELL.REDRAW:
                            CairoLogger.Instance.Debug("Redraw called: " + msg.LParam.ToString());
                            if (Windows.Any(i => i.Handle == msg.LParam))
                            {
                                ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
                                win.UpdateProperties();

                                foreach (ApplicationWindow wind in Windows)
                                {
                                    if (wind.WinFileName == win.WinFileName)
                                    {
                                        wind.UpdateProperties();
                                    }
                                }
                            }
                            else
                            {
                                addWindow(msg.LParam, ApplicationWindow.WindowState.Inactive, true);
                            }
                            break;

                        // TaskMan needs to return true if we provide our own task manager to prevent explorers.
                        // case HSHELL.TASKMAN:
                        //     SingletonLogger.Instance.Info("TaskMan Message received.");
                        //     break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    CairoLogger.Instance.Error("Error in ShellWinProc. ", ex);
                    Debugger.Break();
                }
            }
            else if (msg.Msg == WM_TASKBARCREATEDMESSAGE)
            {
                CairoLogger.Instance.Debug("TaskbarCreated received, setting ITaskbarList window");
                setTaskbarListHwnd();
            }
            else
            {
                // Handle ITaskbarList functions, most not implemented yet

                ApplicationWindow win = null;

                switch (msg.Msg)
                {
                case (int)WM.USER + 50:
                    // ActivateTab
                    // Also sends WM_SHELLHOOK message
                    CairoLogger.Instance.Debug("ITaskbarList: ActivateTab HWND:" + msg.LParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 60:
                    // MarkFullscreenWindow
                    CairoLogger.Instance.Debug("ITaskbarList: MarkFullscreenWindow HWND:" + msg.LParam + " Entering? " + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 64:
                    // SetProgressValue
                    CairoLogger.Instance.Debug("ITaskbarList: SetProgressValue HWND:" + msg.WParam + " Progress: " + msg.LParam);

                    win = new ApplicationWindow(msg.WParam, this);
                    if (Windows.Contains(win))
                    {
                        win = Windows.First(wnd => wnd.Handle == msg.WParam);
                        win.ProgressValue = (int)msg.LParam;
                    }

                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 65:
                    // SetProgressState
                    CairoLogger.Instance.Debug("ITaskbarList: SetProgressState HWND:" + msg.WParam + " Flags: " + msg.LParam);

                    win = new ApplicationWindow(msg.WParam, this);
                    if (Windows.Contains(win))
                    {
                        win = Windows.First(wnd => wnd.Handle == msg.WParam);
                        win.ProgressState = (TBPFLAG)msg.LParam;
                    }

                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 67:
                    // RegisterTab
                    CairoLogger.Instance.Debug("ITaskbarList: RegisterTab MDI HWND:" + msg.LParam + " Tab HWND: " + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 68:
                    // UnregisterTab
                    CairoLogger.Instance.Debug("ITaskbarList: UnregisterTab Tab HWND: " + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 71:
                    // SetTabOrder
                    CairoLogger.Instance.Debug("ITaskbarList: SetTabOrder HWND:" + msg.WParam + " Before HWND: " + msg.LParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 72:
                    // SetTabActive
                    CairoLogger.Instance.Debug("ITaskbarList: SetTabActive HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 75:
                    // Unknown
                    CairoLogger.Instance.Debug("ITaskbarList: Unknown HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 76:
                    // ThumbBarAddButtons
                    CairoLogger.Instance.Debug("ITaskbarList: ThumbBarAddButtons HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 77:
                    // ThumbBarUpdateButtons
                    CairoLogger.Instance.Debug("ITaskbarList: ThumbBarUpdateButtons HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 78:
                    // ThumbBarSetImageList
                    CairoLogger.Instance.Debug("ITaskbarList: ThumbBarSetImageList HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 79:
                    // SetOverlayIcon - Icon
                    CairoLogger.Instance.Debug("ITaskbarList: SetOverlayIcon - Icon HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 80:
                    // SetThumbnailTooltip
                    CairoLogger.Instance.Debug("ITaskbarList: SetThumbnailTooltip HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 81:
                    // SetThumbnailClip
                    CairoLogger.Instance.Debug("ITaskbarList: SetThumbnailClip HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 85:
                    // SetOverlayIcon - Description
                    CairoLogger.Instance.Debug("ITaskbarList: SetOverlayIcon - Description HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;

                case (int)WM.USER + 87:
                    // SetTabProperties
                    CairoLogger.Instance.Debug("ITaskbarList: SetTabProperties HWND:" + msg.WParam);
                    msg.Result = IntPtr.Zero;
                    return;
                }
            }

            msg.Result = DefWindowProc(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
        }
Ejemplo n.º 13
0
        private Boolean HandleInput(Key key)
        {
            _Window.SearchTextBox.Focus();
            switch (key)
            {
            case Key.Enter:
                if (Keyboard.GetKeyStates(Key.LeftCtrl).HasFlag(KeyStates.Down) || Keyboard.GetKeyStates(Key.RightCtrl).HasFlag(KeyStates.Down))
                {
                    if (RunProcess(SearchText))
                    {
                        MinimizeToTray();
                    }
                    return(true);
                }

                if (Windows.Any())
                {
                    if (SelectedWindowIndex <= -1 || Windows.Count <= SelectedWindowIndex)
                    {
                        SelectedWindowIndex = 0;
                    }

                    if (ShowSelectedWindow())
                    {
                        MinimizeToTray();
                        return(true);
                    }
                }
                else if (!String.IsNullOrWhiteSpace(SearchText))
                {
                    if (RunProcess(SearchText))
                    {
                        MinimizeToTray();
                    }
                    return(true);
                }
                return(false);

            case Key.Delete:
                if (Settings.Default.CloseWithShiftDelete && !Keyboard.GetKeyStates(Key.LeftShift).HasFlag(KeyStates.Down) && !Keyboard.GetKeyStates(Key.RightShift).HasFlag(KeyStates.Down))
                {
                    return(false);
                }

                if (!CloseSelectedWindow())
                {
                    return(false);
                }

                var currentSearchText = SearchText;
                _UpdateWindows().ContinueWith(task => Common.RunFromSTAThread(() =>
                {
                    if (!Windows.Any() && SearchText == currentSearchText)
                    {
                        ClearInput();
                    }
                }));
                return(true);

            case Key.Up:
                if (SelectedWindowIndex > 0)
                {
                    SelectedWindowIndex -= 1;
                }
                return(true);

            case Key.Down:
                SelectedWindowIndex = (SelectedWindowIndex == -1)
                        ? 0
                        : Math.Min(Windows.Count - 1, SelectedWindowIndex + 1);
                return(true);

            case Key.PageUp:
                if (Windows.Any())
                {
                    SelectedWindowIndex = 0;
                }
                return(true);

            case Key.PageDown:
                SelectedWindowIndex = Windows.Count - 1;
                return(true);

            case Key.Escape:
                MinimizeToTray();
                return(true);

            default:
                if (Windows.Any() && (SelectedWindowIndex <= -1 || Windows.Count <= SelectedWindowIndex))
                {
                    SelectedWindowIndex = 0;
                }
                return(false);
            }
        }