private void SetBackgroundPath(FilePath value)
        {
            if (Equals(_backgroundPath, value))
            {
                return;
            }

            _backgroundPath = value;

            TargetDesktop.Background =
                _configurationFactory
                .BackgroundFrom(value, _fit);
        }
Пример #2
0
        public IBackground LoadBackground()
        {
            var pathBuffer = new string(default(char), Constants.MaxPath);

            byte tile;
            byte style;

            lock (_ioLock)
            {
                using (var key = uRegistry.CurrentUser.OpenSubKey(
                           Registry.Desktop.SubKey, true))
                {
                    byte.TryParse(key.GetValue(
                                      Registry.Desktop.TileWallpaper.Value).ToString(), out tile);

                    byte.TryParse(key.GetValue(
                                      Registry.Desktop.WallpaperStyle.Value).ToString(), out style);
                }

                NativeMethods.SystemParametersInfo(
                    NativeMethods.SPI_GETDESKWALLPAPER,
                    pathBuffer.Length,
                    pathBuffer,
                    0);

                var path = pathBuffer.Substring(0, pathBuffer.IndexOf(default(char)));

                return(_factory.BackgroundFrom(
                           path,
                           Registry.Desktop.Fit.FromData(tile, style)));
            }
        }
        public IBackground LoadBackground()
        {
            lock (_ioLock)
            {
                try
                {
                    var path = new string(default(char), Constants.MaxPath);
                    _desktop.GetWallpaper(null, ref path);

                    DESKTOP_WALLPAPER_POSITION position;
                    _desktop.GetPosition(out position);

                    return(_factory.BackgroundFrom(
                               path,
                               position.ToFit()));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    return(_factory.BackgroundFrom(string.Empty, Fit.Center));
                }
            }
        }
        // TODO
        //public VirtualDesktopConfiguration(IVirtualDesktop targetDesktop, IConfigurationFactory factory)
        //{
        //    BindToTarget(targetDesktop, factory);
        //    // should take values from desktop
        //    UpdateFromTarget();
        //}

        public void BindToTarget(IVirtualDesktop value, IConfigurationFactory factory)
        {
            _propertyChangedBinding?.Unbind();

            TargetDesktop         = value;
            _configurationFactory = factory;

            if (value == null)
            {
                _backgroundPathSetter = path => ThrowWhenUnbound(nameof(BackgroundPath));
                _fitSetter            = fit => ThrowWhenUnbound(nameof(Fit));

                return;
            }

            _backgroundPathSetter = SetBackgroundPath;
            _fitSetter            = SetFit;

            _propertyChangedBinding = factory.Bind(UpdateFromTarget, value);

            var updateTargetBackground = true;

            // TODO this should have tests for it causing a return
            if (!_backgroundPath.HasValue)
            {
                _backgroundPath        = value.Background.Path;
                updateTargetBackground = false;
            }

            // TODO be sure to fully test that this returns
            if (_fit.Equals(default(Fit)))
            {
                _fit = value.Background.Fit;
                updateTargetBackground = false;
            }

            if (!updateTargetBackground)
            {
                return;
            }

            value.Background = factory.BackgroundFrom(_backgroundPath, _fit);
        }