private async Task ShowAsync()
        {
            _isVisible = true;
            if (!_mouseHook.IsHookSet)
            {
                _mouseHook.SetHook();
            }
            var animation = new DoubleAnimation
            {
                To             = 1,
                Duration       = TimeSpan.FromMilliseconds(300),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseOut
                },
            };

            _dropShadow.Show();
            Show();
            NativeMethods.BringWindowToTop(Handle);

            BeginAnimation(OpacityProperty, animation);
            _dropShadow.BeginAnimation(WindowDropShadow.OpacityProperty, animation);
            await Task.Delay((int)animation.Duration.TimeSpan.TotalMilliseconds / 2);

            WindowBlur.Enable(this, preferAcrylic: false);
            await Task.Delay((int)animation.Duration.TimeSpan.TotalMilliseconds / 2);
        }
Exemple #2
0
 protected void StartCapture()
 {
     if (GestureMachine == null)
     {
         throw new InvalidOperationException();
     }
     mouseHook.SetHook();
 }
Exemple #3
0
        public void DisposeWhenActivatedTest()
        {
            var hook = new LowLevelMouseHook((evnt, data) => { return(LowLevelMouseHook.Result.Transfer); });

            hook.SetHook();
            Assert.IsTrue(hook.IsActivated);
            hook.Dispose();
            Assert.IsFalse(hook.IsActivated);
        }
Exemple #4
0
        public void SetHookThrowsInvalidOperationExceptionTest()
        {
            var hook = new LowLevelMouseHook((evnt, data) => { return(LowLevelMouseHook.Result.Transfer); });

            hook.SetHook();
            try
            {
                hook.SetHook();
            }
            catch (InvalidOperationException)
            {
                return;
            }
            finally
            {
                hook.Unhook();
            }
            Assert.Fail();
        }
Exemple #5
0
        public void LowLevelMouseHookProcTest()
        {
            var sender = new SingleInputSender();
            var list   = new List <LowLevelMouseHook.Event>();
            var hook   = new LowLevelMouseHook((evnt, data) => {
                if (data.fromCreviceApp)
                {
                    list.Add(evnt);
                    return(LowLevelMouseHook.Result.Cancel);
                }
                return(LowLevelMouseHook.Result.Transfer);
            });

            Assert.AreEqual(list.Count, 0);
            hook.SetHook();
            sender.RightClick();
            hook.Unhook();
            Assert.AreEqual(list.Count, 2);
        }
        protected override void OnInitialized(EventArgs eventArgs)
        {
            base.OnInitialized(eventArgs);

            try
            {
                instance = this;
                // Update the position and size of the window.
                UpdatePosition();
                // Set the window as NO_ACTIVATE, TOOLWINDOW and TOPMOST,
                WindowStyles.SetExtended(this, WindowStyles.GetExtended(this)
                                         | ExtendedWindowStyle.WS_EX_NOACTIVATE
                                         | ExtendedWindowStyle.WS_EX_TOOLWINDOW
                                         | ExtendedWindowStyle.WS_EX_TOPMOST);

                // Apply the user-selected locale.
                IntlManager.Apply(new CultureInfo(AppState.Current.UserSettings.Locale));
                // Apply the user-selected theme.
                ThemeManager.Apply(AppState.Current.UserSettings.Theme);

                // Initialize the drop shadow.
                _dropShadow = new WindowDropShadow(this)
                {
                    Radius   = 15.0,
                    Strength = 2.0,
                    Opacity  = 0.0,
                };

                // Set the window's view-model.
                _viewModel = new OverviewViewModel();

                InitializeQuickInfoWindow();

                // Request the needed window permissions. (>= Windows 8)
                _clipboardPermission = new UIPermission(PermissionState.Unrestricted)
                {
                    Clipboard = UIPermissionClipboard.AllClipboard
                };

                // Setup the clipboard manager and the according event listeners.
                _clipboardManager = new ClipboardManager(this);
                _clipboardManager.StateChanged += OnClipboardStateChanged;

                // Initially hidden.
                _isVisible   = false;
                _transitions = new TaskChain();

                // Initialize the window message receiver with a name.
                _wmr = new WindowMessageReceiver("MULTICLIP_IPC", null);
                // Setup the IPC handler.
                _wmr.MessageReceived += OnMessageReceived;

                // Initialize and set the low-level mouse hook.
                _mouseHook              = new LowLevelMouseHook();
                _mouseHook.LButtonDown += OnMouseHookButtonDown;
                _mouseHook.RButtonDown += OnMouseHookButtonDown;
                _mouseHook.XButtonDown += OnMouseHookButtonDown;
                _mouseHook.SetHook();

                // Initialize and register the overview hotkey.
                _overviewHotkey          = new GlobalHotkey(HotkeyModfier.Ctrl, Keys.Space);
                _overviewHotkey.Pressed += OnOverviewHotkeyPressed;
                _overviewHotkey.Register();

                // Initialize and register the secure-copy hotkey.
                _secureCopyHotkey          = new GlobalHotkey(HotkeyModfier.Ctrl | HotkeyModfier.Alt, Keys.C);
                _secureCopyHotkey.Pressed += OnSecureCopyHotkeyPressed;
                _secureCopyHotkey.Register();

                // Show the help window on the first run of the app.
                if ((bool)Properties.Settings.Default["IsFirstRun"] == true)
                {
                    Properties.Settings.Default["IsFirstRun"] = false;
                    Properties.Settings.Default.Save();
                    HelpWindow helpWindow = new HelpWindow();
                    helpWindow.Show();
                }

                ClipboardList.ItemsSource = _viewModel.ClipboardItems;

                // When a file-drop item is about to open a subwindow,
                // hide the main window.
                FileDropItem.PreviewShellExecute += delegate
                {
                    if (_isVisible)
                    {
                        HideAsync().GetAwaiter();
                    }
                };
            }
            catch (Exception e)
            {
                _logger.LogCritical(LogEvents.FatalErr, "Failed to initialize the main window!", e);
                Exceptions.NotifyCritical(e);
            }
        }
Exemple #7
0
 public static void ClassInit(TestContext context)
 {
     mouseHook.SetHook();
 }