public CanvasWindowGestureView(GestureParser gestureParser)
        {
            _gestureParser = gestureParser;
            RegisterEventHandlers();
            var waitCanvasWindow = new AutoResetEvent(false);
            new Thread(() =>
            {
                _canvasWindow = new CanvasWindow()
                {
                    //最初的时候放在屏幕以外
                    Visible = false,
                    IgnoreInput = true,
                    NoActivate = true,
                    TopMost = true
                };
                waitCanvasWindow.Set();
                _canvasWindow.ShowDialog();
            }) { Name = "CanvasWindow" }.Start();

            waitCanvasWindow.WaitOne();

            InitDefaultProperties();
            _fadeOuTimer.Elapsed += OnFadeOutTimerElapsed;
            SystemEvents.DisplaySettingsChanged += SystemDisplaySettingsChanged;
        }
Exemplo n.º 2
0
        public ExecutionResult Execute(GestureContext context, GestureParser gestureParser)
        {
            //Aware接口依赖注入
            var contextAware = Command as IGestureContextAware;
            if (contextAware != null) contextAware.Context = context;

            var parserAware = this.Command as IGestureParserAware;
            if (parserAware != null) parserAware.Parser = gestureParser;

            //在独立线程中运行
            //new Thread似乎反应快一点,ThreadPool似乎有延迟
            //ThreadPool.QueueUserWorkItem((s) =>
            //new Thread(() =>
            {
                try
                {
                    context.ActivateTargetWindow();
                    Command.Execute();
                }
                catch (Exception)
                {
                    //ignore errors for now
            #if DEBUG
                    throw;
            #endif
                }
            }//) { IsBackground = false}.Start();

            return new ExecutionResult(null, true);
        }
Exemplo n.º 3
0
        public ExecutionResult Execute(GestureContext context, GestureParser gestureParser)
        {
            //Aware接口依赖注入
            var contextAware = Command as IGestureContextAware;

            if (contextAware != null)
            {
                contextAware.Context = context;
            }

            var parserAware = this.Command as IGestureParserAware;

            if (parserAware != null)
            {
                parserAware.Parser = gestureParser;
            }

            //var intentStoreAware = Command as IGestureIntentStoreAware;
            //if (intentStoreAware != null) intentStoreAware.IntentStore = null;


            var shouldInit = this.Command as INeedInit;

            if (shouldInit != null && !shouldInit.IsInitialized)
            {
                shouldInit.Init();
            }

            //在独立线程中运行
            //new Thread似乎反应快一点,ThreadPool似乎有延迟
            //ThreadPool.QueueUserWorkItem((s) =>
            //new Thread(() =>
            {
                try
                {
                    context.ActivateTargetWindow();
                    Command.Execute();
                    using (var proc = Process.GetCurrentProcess())
                    {
                        Native.SetProcessWorkingSetSize(proc.Handle, -1, -1);
                    }
                }
                catch (Exception)
                {
                    //ignore errors for now
#if DEBUG
                    throw;
#endif
                }
            }//) { IsBackground = false}.Start();

            return(new ExecutionResult(null, true));
        }
Exemplo n.º 4
0
        public SettingsFormController(IConfig config, GestureParser parser,
            Win32MousePathTracker2 pathTracker, JsonGestureIntentStore intentStore,
            CanvasWindowGestureView gestureView)
        {
            _config = config;
            _parser = parser;
            _pathTracker = pathTracker;
            _intentStore = intentStore;
            _gestureView = gestureView;

            #region 初始化支持的命令和命令视图
            //Add Command Types
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(DoNothingCommand)), typeof(DoNothingCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(HotKeyCommand)), typeof(HotKeyCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WebSearchCommand)), typeof(WebSearchCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WindowControlCommand)), typeof(WindowControlCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(TaskSwitcherCommand)), typeof(TaskSwitcherCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(OpenFileCommand)), typeof(OpenFileCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(SendTextCommand)), typeof(SendTextCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(GotoUrlCommand)), typeof(GotoUrlCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(CmdCommand)), typeof(CmdCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(ScriptCommand)), typeof(ScriptCommand));

            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(PauseWGesturesCommand)), typeof(PauseWGesturesCommand));
            SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(ChangeAudioVolumeCommand)), typeof(ChangeAudioVolumeCommand));
            
            CommandViewFactory.Register<OpenFileCommand, OpenFileCommandView>();
            CommandViewFactory.Register<DoNothingCommand, GeneralNoParameterCommandView>();
            CommandViewFactory.Register<HotKeyCommand, HotKeyCommandView>();
            CommandViewFactory.Register<GotoUrlCommand, GotoUrlCommandView>();
            CommandViewFactory.Register<PauseWGesturesCommand, GeneralNoParameterCommandView>();
            CommandViewFactory.Register<WebSearchCommand, WebSearchCommandView>();
            CommandViewFactory.Register<WindowControlCommand, WindowControlCommandView>();
            CommandViewFactory.Register<CmdCommand, CmdCommandView>();
            CommandViewFactory.Register<SendTextCommand, SendTextCommandView>();
            CommandViewFactory.Register<TaskSwitcherCommand, TaskSwitcherCommandView>();
            CommandViewFactory.Register<ScriptCommand, ScriptCommandView>();
            CommandViewFactory.Register<ChangeAudioVolumeCommand, GeneralNoParameterCommandView>();
            #endregion

            #region Hotcorner 
            SupportedHotCornerCommands.Add(NamedAttribute.GetNameOf(typeof(DoNothingCommand)), typeof(DoNothingCommand));
            SupportedHotCornerCommands.Add(NamedAttribute.GetNameOf(typeof(HotKeyCommand)), typeof(HotKeyCommand));

            HotCornerCommandViewFactory.Register<DoNothingCommand, GeneralNoParameterCommandView>();
            HotCornerCommandViewFactory.Register<HotKeyCommand, HotKeyCommandView>();
            #endregion

            _form = new SettingsForm(this);
        }
Exemplo n.º 5
0
        public ExecutionResult Execute(GestureContext context, GestureParser gestureParser)
        {
            //Aware接口依赖注入
            var contextAware = Command as IGestureContextAware;
            if (contextAware != null) contextAware.Context = context;

            var parserAware = this.Command as IGestureParserAware;
            if (parserAware != null) parserAware.Parser = gestureParser;

            var shouldInit = this.Command as INeedInit;
            if (shouldInit != null && !shouldInit.IsInitialized)
            {
                shouldInit.Init();
            }
            
            //在独立线程中运行
            //new Thread似乎反应快一点,ThreadPool似乎有延迟
            //ThreadPool.QueueUserWorkItem((s) =>
            //new Thread(() =>
            {
                try
                {
                    context.ActivateTargetWindow();
                    Command.Execute();
                    using (var proc = Process.GetCurrentProcess())
                    {
                        Native.SetProcessWorkingSetSize(proc.Handle, -1, -1);
                    }
                }
                catch (Exception)
                {
                    //ignore errors for now
#if DEBUG
                    throw;
#endif
                }
            }//) { IsBackground = false}.Start();

            return new ExecutionResult(null, true);

        }
Exemplo n.º 6
0
        public ExecutionResult Execute(GestureContext context, GestureParser gestureParser)
        {
            //Aware接口依赖注入
            var contextAware = Command as IGestureContextAware;

            if (contextAware != null)
            {
                contextAware.Context = context;
            }

            var parserAware = this.Command as IGestureParserAware;

            if (parserAware != null)
            {
                parserAware.Parser = gestureParser;
            }


            //在独立线程中运行
            //new Thread似乎反应快一点,ThreadPool似乎有延迟
            //ThreadPool.QueueUserWorkItem((s) =>
            new Thread(() =>
            {
                try
                {
                    Command.Execute();
                }
                catch (Exception)
                {
                    //ignore errors for now
#if DEBUG
                    throw;
#endif
                }
            })
            {
                IsBackground = false
            }.Start();

            return(new ExecutionResult(null, true));
        }
Exemplo n.º 7
0
        //如果inApp不为null, 则为编辑模式
        public EditGestureForm(GestureParser gestureParser, AbstractApp inApp, GestureIntent intent = null)
        {
            _gestureParser = gestureParser;
            _app = inApp;
            _intent = intent;

            InitializeComponent();

            if (_intent != null)
            {
                if (inApp.Find(intent.Gesture) != intent)
                {
                    throw new InvalidOperationException("intent必须是inApp中的");
                }
                Text = "编辑手势";
                lb_mnemonic.Text = _intent.Gesture.ToString();
                tb_gestureName.Text = _intent.Name;
            }
            BeginCapture();

        }
Exemplo n.º 8
0
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;

            if (CommandViewFactory != null)
            {
                CommandViewFactory.Dispose();
            }

            _config = null;
            _parser = null;
            _gestureView = null;
            _intentStore = null;
            _pathTracker = null;

            SupportedCommands.Clear();
            SupportedCommands = null;
            CommandViewFactory = null;

            _form.Dispose();
            _form = null;

            //GC.Collect();
        }
Exemplo n.º 9
0
        private static void ConfigureComponents()
        {
            #region Create Components
            intentFinder = new Win32GestrueIntentFinder(intentStore);
            var pathTracker = new Win32MousePathTracker2();
            gestureParser = new GestureParser(pathTracker, intentFinder);

            gestureView = new CanvasWindowGestureView(gestureParser);

            componentsToDispose.Add(gestureParser);
            componentsToDispose.Add(gestureView);
            componentsToDispose.Add(pathTracker);
            #endregion

            #region pathTracker
            pathTracker.DisableInFullscreen = config.Get(ConfigKeys.PathTrackerDisableInFullScreen, true);
            pathTracker.PreferWindowUnderCursorAsTarget = config.Get(ConfigKeys.PathTrackerPreferCursorWindow, false);
            pathTracker.TriggerButton = (Win32MousePathTracker2.GestureTriggerButton)config.Get(ConfigKeys.PathTrackerTriggerButton, Win32MousePathTracker2.GestureTriggerButton.Right);
            pathTracker.InitialValidMove = config.Get(ConfigKeys.PathTrackerInitialValidMove, 4);
            pathTracker.StayTimeout = config.Get(ConfigKeys.PathTrackerStayTimeout, true);
            pathTracker.StayTimeoutMillis = config.Get(ConfigKeys.PathTrackerStayTimeoutMillis, 500);
            pathTracker.InitialStayTimeout = config.Get(ConfigKeys.PathTrackerInitialStayTimeout, true);
            pathTracker.InitialStayTimeoutMillis = config.Get(ConfigKeys.PathTrackerInitialStayTimoutMillis, 150);
            pathTracker.RequestPauseResume += paused => menuItem_pause_Click(null,EventArgs.Empty);
            pathTracker.RequestShowHideTray += ToggleTrayIconVisibility ;
            #endregion

            #region gestureView
            gestureView.ShowPath = config.Get(ConfigKeys.GestureViewShowPath, true);
            gestureView.ShowCommandName = config.Get(ConfigKeys.GestureViewShowCommandName, true);
            gestureView.ViewFadeOut = config.Get(ConfigKeys.GestureViewFadeOut, true);
            gestureView.PathMainColor = Color.FromArgb(config.Get(ConfigKeys.GestureViewMainPathColor, gestureView.PathMainColor.ToArgb()));
            gestureView.PathAlternativeColor = Color.FromArgb(config.Get(ConfigKeys.GestureViewAlternativePathColor, gestureView.PathAlternativeColor.ToArgb()));
            gestureView.PathMiddleBtnMainColor = Color.FromArgb(config.Get(ConfigKeys.GestureViewMiddleBtnMainColor, gestureView.PathMiddleBtnMainColor.ToArgb()));
            #endregion
            
            #region GestureParser
            gestureParser.EnableHotCorners = config.Get(ConfigKeys.GestureParserEnableHotCorners, true);
            gestureParser.Enable8DirGesture = config.Get(ConfigKeys.GestureParserEnable8DirGesture, true);
            #endregion
        }