Esempio n. 1
0
 private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is Window window)
     {
         if (true.Equals(e.OldValue))
         {
             GetWindowBlur(window)?.Detach();
             window.ClearValue(WindowBlurProperty);
         }
         if (true.Equals(e.NewValue))
         {
             var blur = new WindowBlur();
             blur.Attach(window);
             window.SetValue(WindowBlurProperty, blur);
         }
     }
 }
Esempio n. 2
0
 private void Build()
 {
     try
     {
         // Setup window
         this.WindowState = WindowState.Normal;
         this.Left        = Screen.PrimaryScreen.WorkingArea.Left;
         this.Top         = Screen.PrimaryScreen.WorkingArea.Top;
         this.Width       = Screen.PrimaryScreen.WorkingArea.Width;
         this.Height      = 18;
         // Use Windows API to create margin for bar
         WinApi.RECT rect = new WinApi.RECT();
         rect.left   = Screen.PrimaryScreen.WorkingArea.Left;
         rect.top    = Screen.PrimaryScreen.WorkingArea.Top;
         rect.right  = Screen.PrimaryScreen.WorkingArea.Right;
         rect.bottom = Screen.PrimaryScreen.WorkingArea.Bottom;
         WinApi.APPBARDATA appbardata = new WinApi.APPBARDATA();
         appbardata.rc     = rect;
         appbardata.cbSize = Marshal.SizeOf((object)appbardata);
         appbardata.hWnd   = this.handle;
         appbardata.uEdge  = 1;
         WinApi.SHAppBarMessage(0, ref appbardata);
         WinApi.SHAppBarMessage(2, ref appbardata);
         appbardata.rc.bottom = checked (appbardata.rc.top + Convert.ToInt32(18));
         WinApi.SHAppBarMessage(3, ref appbardata);
         // Get config
         dynamic cfg = null;
         try
         {
             cfg = this.ReadConfig();
         }
         catch (Exception err)
         {
             System.Windows.MessageBox.Show(err.Message, "Failed to load config!");
             throw err;
         }
         // Load extentions
         foreach (string dll in Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TopBar", "extensions"), "*.dll"))
         {
             this.Extentions.Add(Assembly.LoadFile(dll));
         }
         // Alert if blur disabled
         // if (this.Config != null && (bool)this.Config.settings["use-blur"] && !(bool)cfg.settings["use-blur"])
         //     System.Windows.MessageBox.Show("You must restart TopBar to disable blur!", "Restart to disable blur");
         // Save config
         this.Config = cfg;
         // Enable blur
         if (!this.isBlured && (bool)this.Config.settings["use-blur"])
         {
             this.isBlured = true;
             WindowBlur.SetIsEnabled(this, true);
         }
         // Set backgroud
         this.Background = new SolidColorBrush(Color.FromArgb(
                                                   (byte)this.Config.settings.color.alpha,
                                                   (byte)this.Config.settings.color.red,
                                                   (byte)this.Config.settings.color.green,
                                                   (byte)this.Config.settings.color.blue
                                                   ));
         // Setup focused window title styles
         this.WindowName.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString((string)this.Config.settings["current-window"].color));
         // Setup widgets
         try
         {
             this.SetupWidgets(this.Config);
         }
         catch (Exception err)
         {
             System.Windows.MessageBox.Show(err.ToString(), "Failed to setup widgets!");
             throw new Exception("");
         }
     }
     catch (Exception err) {
         if (err.Message.Length > 0)
         {
             System.Windows.MessageBox.Show(err.ToString(), "Failed to load TopBar!");
         }
     }
 }
Esempio n. 3
0
 public static void SetWindowBlur(DependencyObject element, WindowBlur value)
 {
     element.SetValue(WindowBlurProperty, value);
 }