Example #1
0
        /// <summary>
        /// Deep Copy
        /// </summary>
        /// <returns></returns>
        public MonitorSettings Clone()
        {
            var clone = new MonitorSettings(0);

            clone.Settings.Clear();

            foreach (var list in this.Settings)
            {
                var children = new ObservableCollection <WallpaperSettings>(list.Select(x => x.Clone()));
                clone.Settings.Add(children);
            }

            clone.ActiveSetting = this.ActiveSetting;
            clone.RotateDevice  = this.RotateDevice;

            return(clone);
        }
        /// <summary>
        /// ディスプレイを回転した後、画面の向きに対応した壁紙を設定する
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="increment"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public async Task RotateAndChangeWallPaperAsync(MonitorSettings settings, int increment, IObserver<int> progress)
        {
            if (MonitorCount == 0)
            {
                return;
            }

            //画面を回転させるオブジェクトを取得
            var rotate = DisplayRotate.Generate(settings.RotateDevice % MonitorCount);

            if (rotate == null)
            {
                return;
            }
            

            //回転中は画面がちらつくので暗転させる
            using (increment != 0 ? new DisplayBlackOut(blackoutTime) : Disposable.Empty)//
            {
                await Task.Delay(100);

                //画面を回転
                rotate.Rotate(increment);

                await Task.Delay(100);

                //壁紙を設定
                this.RefreshWallpaper(settings);

                await Task.Delay(1000);
            }

            progress.OnNext(1);

            if (increment != 0)
            {
                //壁紙が正しく変更されないことがあるので、時間がたったら再度壁紙を設定
                await Task.Delay(2500);
                this.RefreshWallpaper(settings);
            }

            progress.OnCompleted();
            
        }
        /// <summary>
        /// Deep Copy
        /// </summary>
        /// <returns></returns>
        public MonitorSettings Clone()
        {
            var clone = new MonitorSettings(0);
            clone.Settings.Clear();

            foreach (var list in this.Settings)
            {
                var children = new ObservableCollection<WallpaperSettings>(list.Select(x => x.Clone()));
                clone.Settings.Add(children);
            }

            clone.ActiveSetting = this.ActiveSetting;
            clone.RotateDevice = this.RotateDevice;

            return clone;
        }
        /// <summary>
        /// 全モニタの壁紙を再設定
        /// </summary>
        /// <param name="settings"></param>
        public void RefreshWallpaper(MonitorSettings settings)
        {
            for (int monitorIndex = 0; monitorIndex < MonitorCount; monitorIndex++)
            {
                var mode = new DeviceMode(monitorIndex);

                //デバイス情報を取得できないか、設定が存在しない場合はスキップ
                if (!mode.IsSucceeded || !settings.Current.ContainsIndex(monitorIndex))
                {
                    continue;
                }

                //壁紙のファイルパスと表示方法の設定を読み込み
                var setting = settings.Current[monitorIndex]
                    .OrientationSettings[(DisplayOrientations)mode.Mode.dmDisplayOrientation];

                //壁紙を設定
                if (setting != null && setting.Path != null && setting.Path.Length > 0)
                {
                    this.ChangeWallpaper(monitorIndex, setting.Path, setting.Position);
                }
            }
        }