Ejemplo n.º 1
0
 private void closeShadow()
 {
     if (shadow != null && !shadow.IsClosing)
     {
         shadow.Close();
         shadow = null;
     }
 }
Ejemplo n.º 2
0
 private void setupShadow()
 {
     if (Settings.Instance.EnableMenuBarShadow && shadow == null && AppBarEdge != AppBarEdge.Bottom)
     {
         shadow = new MenuBarShadow(_cairoApplication, _windowManager, this);
         shadow.Show();
         setShadowPosition();
     }
 }
Ejemplo n.º 3
0
 private void setupShadow()
 {
     if (Settings.Instance.EnableMenuBarShadow && shadow == null && !secretBottomMenuBar)
     {
         shadow = new MenuBarShadow(this);
         shadow.Show();
         setShadowPosition();
     }
 }
Ejemplo n.º 4
0
        public static void Main()
        {
            if (!SingleInstanceCheck())
            {
                return;
            }

            // If framework is not correct version then quit.
            if (!FrameworkCheck())
            {
                return;
            }

            InitializeParentWindow();

            App app = new App();

            MenuBarWindow = new MenuBar() { Owner = _parentWindow };
            MenuBarWindow.Show();
            app.MainWindow = MenuBarWindow;

#if (ENABLEFIRSTRUN)
            FirstRun(app);
#endif

            if (Properties.Settings.Default.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow() { Owner = _parentWindow };
                MenuBarShadowWindow.Show();
            }

            if (Properties.Settings.Default.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar() { Owner = _parentWindow };
                TaskbarWindow.Show();
            }

            if (Properties.Settings.Default.EnableDesktop)
            {
                DesktopWindow = new Desktop() { Owner = _parentWindow };
                DesktopWindow.Show();
            }
            
            app.Run();

        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            #region Args

            if (args.Length > 0 && args[0] == "/restart")
            {
                isRestart = true;
            }
            else
            {
                isRestart = false;
            }

            if (args.Length > 0 && args[0] == "/tour")
            {
                isTour = true;
            }
            else
            {
                isTour = false;
            }

            #endregion

            #region Single Instance Check
            bool ok;
            cairoMutex = new System.Threading.Mutex(true, "CairoShell", out ok);

            if (!ok && !isRestart)
            {
                // Another instance is already running.
                return;
            }
            else if (!ok && isRestart)
            {
                // this is a restart so let's wait for the old instance to end
                System.Threading.Thread.Sleep(2000);
            }
            #endregion

            #region some real shell code
            int hShellReadyEvent;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Shell.IsWindows2kOrBetter)
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, true, @"Global\msgina: ShellReadyEvent");
            }
            else
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, false, "msgina: ShellReadyEvent");
            }

            if (hShellReadyEvent != 0)
            {
                NativeMethods.SetEvent(hShellReadyEvent);
                NativeMethods.CloseHandle(hShellReadyEvent);
            }
            #endregion

            // an attempt to relaunch explorer it the application gets closed. doesnt work if VS terminates execution
            // AppDomain.CurrentDomain.ProcessExit += (o, e) => Shutdown();

            #region InitializationRoutines

            SetupLoggingSystem();
            WriteApplicationDebugInfoToConsole();

            SetupPluginSystem();

            #endregion

            // check if we are the current user's shell
            // set here as well so that we don't behave differently once user changes setting
            IsCairoUserShell = Shell.IsCairoUserShell;

            // Before we do anything, check if settings need to be upgraded
            if (Settings.IsFirstRun == true)
            {
                Settings.Upgrade();
            }

            if (Settings.EnableDesktop)
            {
                // hide the windows desktop
                Shell.ToggleDesktopIcons(false);
            }

            App app = new App();
            app.InitializeComponent();

            // Set custom theme if selected
            string theme = Settings.CairoTheme;
            if (theme != "Default")
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + theme))
                {
                    app.Resources.MergedDictionaries.Add((ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme)));
                }
            }

            if (Settings.EnableTaskbar)
            {
                // hide Windows taskbar
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarPos((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            MenuBarWindow  = new MenuBar(System.Windows.Forms.Screen.PrimaryScreen);
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();
            MenuBarWindows.Add(MenuBarWindow);

            if (Settings.EnableDesktop)
            {
                DesktopWindow = new Desktop();
                DesktopWindow.Show();
            }

            if (Settings.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow(MenuBarWindow, System.Windows.Forms.Screen.PrimaryScreen);
                MenuBarShadowWindow.Show();
                MenuBarShadowWindows.Add(MenuBarShadowWindow);
            }

            if (Settings.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar(System.Windows.Forms.Screen.PrimaryScreen);
                TaskbarWindow.Show();
                TaskbarWindows.Add(TaskbarWindow);
            }

            if (Settings.EnableMenuBarMultiMon || Settings.EnableTaskbarMultiMon)
            {
                ScreenSetup(true);
            }
            else if (IsCairoUserShell) // Set desktop work area for when Explorer isn't running
            {
                AppBarHelper.SetWorkArea(System.Windows.Forms.Screen.PrimaryScreen);
            }

            // initialize system tray if enabled
            if (Settings.EnableSysTray == true)
            {
                NotificationArea.Instance.Initialize();
            }

#if (ENABLEFIRSTRUN)
            FirstRun();
#endif

            // login items only necessary if Explorer didn't start them
            if (IsCairoUserShell && !isRestart)
            {
                RunStartupApps();
            }

            app.Run();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Compares the system screen list to the screens associated with Cairo windows, then creates or destroys windows as necessary.
        /// Only affects non-primary screens, as Cairo always opens on at least the primary screen.
        /// Runs at startup and when a WM_DISPLAYCHANGE message is received by the main MenuBar window.
        /// </summary>
        public static void ScreenSetup(bool skipChecks = false)
        {
            lock (screenSetupLock)
            {
                IsSettingScreens = true;

                List <string> sysScreens     = new List <string>();
                List <string> openScreens    = new List <string>();
                List <string> addedScreens   = new List <string>();
                List <string> removedScreens = new List <string>();

                ResetScreenCache();

                if (!skipChecks)
                {
                    // enumerate screens

                    if (Settings.EnableMenuBarMultiMon || !Settings.EnableTaskbar)
                    {
                        foreach (MenuBar bar in MenuBarWindows)
                        {
                            if (bar.Screen != null)
                            {
                                openScreens.Add(bar.Screen.DeviceName);
                            }
                        }
                    }
                    else if (Settings.EnableTaskbarMultiMon)
                    {
                        foreach (Taskbar bar in TaskbarWindows)
                        {
                            if (bar.Screen != null)
                            {
                                openScreens.Add(bar.Screen.DeviceName);
                            }
                        }
                    }
                    else
                    {
                        return;
                    }

                    foreach (var screen in System.Windows.Forms.Screen.AllScreens)
                    {
                        Trace.WriteLine(string.Format("{0} found at {1} with area {2}; primary? {3}", screen.DeviceName, screen.Bounds.ToString(), screen.WorkingArea.ToString(), screen.Primary.ToString()));

                        sysScreens.Add(screen.DeviceName);
                    }

                    // figure out which screens have been added vs removed

                    foreach (string name in sysScreens)
                    {
                        if (!openScreens.Contains(name))
                        {
                            addedScreens.Add(name);
                        }
                    }

                    foreach (string name in openScreens)
                    {
                        if (!sysScreens.Contains(name))
                        {
                            removedScreens.Add(name);
                        }
                    }

                    if (removedScreens.Count == sysScreens.Count)
                    {
                        // remove everything?! no way!
                        return;
                    }

                    // close windows associated with removed screens
                    foreach (string name in removedScreens)
                    {
                        // close taskbars
                        Taskbar taskbarToClose = null;
                        foreach (Taskbar bar in TaskbarWindows)
                        {
                            if (bar.Screen != null && bar.Screen.DeviceName == name)
                            {
                                taskbarToClose = bar;
                                break;
                            }
                        }

                        if (taskbarToClose != null)
                        {
                            taskbarToClose.Close();
                            TaskbarWindows.Remove(taskbarToClose);
                        }

                        // close menu bars
                        MenuBar barToClose = null;
                        foreach (MenuBar bar in MenuBarWindows)
                        {
                            if (bar.Screen != null && bar.Screen.DeviceName == name)
                            {
                                barToClose = bar;
                                break;
                            }
                        }

                        if (barToClose != null)
                        {
                            if (!barToClose.IsClosing)
                            {
                                barToClose.Close();
                            }
                            MenuBarWindows.Remove(barToClose);
                        }

                        // close menu bar shadows
                        MenuBarShadow barShadowToClose = null;
                        foreach (MenuBarShadow bar in MenuBarShadowWindows)
                        {
                            if (bar.Screen != null && bar.Screen.DeviceName == name)
                            {
                                barShadowToClose = bar;
                                break;
                            }
                        }

                        if (barShadowToClose != null)
                        {
                            if (!barShadowToClose.IsClosing)
                            {
                                barShadowToClose.Close();
                            }
                            MenuBarShadowWindows.Remove(barShadowToClose);
                        }
                    }

                    // update screens of stale windows
                    foreach (MenuBar bar in MenuBarWindows)
                    {
                        if (bar.Screen != null)
                        {
                            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                            {
                                if (screen.DeviceName == bar.Screen.DeviceName)
                                {
                                    bar.Screen = screen;
                                    break;
                                }
                            }
                        }
                    }

                    foreach (MenuBarShadow bar in MenuBarShadowWindows)
                    {
                        if (bar.Screen != null)
                        {
                            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                            {
                                if (screen.DeviceName == bar.Screen.DeviceName)
                                {
                                    bar.Screen = screen;
                                    break;
                                }
                            }
                        }
                    }

                    foreach (Taskbar bar in TaskbarWindows)
                    {
                        if (bar.Screen != null)
                        {
                            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                            {
                                if (screen.DeviceName == bar.Screen.DeviceName)
                                {
                                    bar.Screen = screen;
                                    bar.setPosition();
                                    break;
                                }
                            }
                        }
                    }
                }

                // open windows on newly added screens
                foreach (var screen in System.Windows.Forms.Screen.AllScreens)
                {
                    if ((skipChecks && !screen.Primary) || addedScreens.Contains(screen.DeviceName))
                    {
                        if (Settings.EnableMenuBarMultiMon)
                        {
                            // menu bars
                            MenuBar newMenuBar = new MenuBar(screen);
                            newMenuBar.Show();
                            MenuBarWindows.Add(newMenuBar);

                            if (Settings.EnableMenuBarShadow)
                            {
                                // menu bar shadows
                                MenuBarShadow newMenuBarShadow = new MenuBarShadow(newMenuBar, screen);
                                newMenuBarShadow.Show();
                                MenuBarShadowWindows.Add(newMenuBarShadow);
                            }
                        }

                        if (Settings.EnableTaskbarMultiMon && Settings.EnableTaskbar)
                        {
                            // taskbars
                            Taskbar newTaskbar = new Taskbar(screen);
                            newTaskbar.Show();
                            TaskbarWindows.Add(newTaskbar);
                        }
                    }

                    // Set desktop work area for when Explorer isn't running
                    if (IsCairoUserShell)
                    {
                        AppBarHelper.SetWorkArea(screen);
                    }
                }

                IsSettingScreens = false;
            }
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            #region Initialization Routines

            ProcessCommandLineArgs(args);
            SingleInstanceCheck();
            SetShellReadyEvent();

            SetupLoggingSystem();
            WriteApplicationDebugInfoToConsole();

            SetupPluginSystem();

            #endregion

            // check if we are the current user's shell
            // set here as well so that we don't behave differently once user changes setting
            IsCairoUserShell = Shell.IsCairoUserShell;

            // Before we do anything, check if settings need to be upgraded
            if (Settings.IsFirstRun == true)
            {
                Settings.Upgrade();
            }

            if (Settings.EnableDesktop)
            {
                // hide the windows desktop
                Shell.ToggleDesktopIcons(false);
            }

            App app = new App();
            app.InitializeComponent();

            // Set custom theme if selected
            string theme = Settings.CairoTheme;
            if (theme != "Default")
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + theme))
                {
                    app.Resources.MergedDictionaries.Add((ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme)));
                }
            }

            if (Settings.EnableTaskbar)
            {
                // hide Windows taskbar
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarPos((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            MenuBarWindow  = new MenuBar(System.Windows.Forms.Screen.PrimaryScreen);
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();
            MenuBarWindows.Add(MenuBarWindow);

            if (Settings.EnableDesktop)
            {
                DesktopWindow = new Desktop();
                DesktopWindow.Show();
            }

            if (Settings.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow(MenuBarWindow, System.Windows.Forms.Screen.PrimaryScreen);
                MenuBarShadowWindow.Show();
                MenuBarShadowWindows.Add(MenuBarShadowWindow);
            }

            if (Settings.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar(System.Windows.Forms.Screen.PrimaryScreen);
                TaskbarWindow.Show();
                TaskbarWindows.Add(TaskbarWindow);
            }

            if (Settings.EnableMenuBarMultiMon || Settings.EnableTaskbarMultiMon)
            {
                ScreenSetup(true);
            }
            else if (IsCairoUserShell) // Set desktop work area for when Explorer isn't running
            {
                AppBarHelper.SetWorkArea(System.Windows.Forms.Screen.PrimaryScreen);
            }

            // initialize system tray if enabled
            if (Settings.EnableSysTray == true)
            {
                NotificationArea.Instance.Initialize();
            }

#if (ENABLEFIRSTRUN)
            FirstRun();
#endif

            // login items only necessary if Explorer didn't start them
            if (IsCairoUserShell && !isRestart)
            {
                RunStartupApps();
            }

            app.Run();
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            #region Initialization Routines

            ProcessCommandLineArgs(args);
            SingleInstanceCheck();
            SetShellReadyEvent();

            SetupSettings(); // run this before logging setup so that preferences are always used
            SetupLoggingSystem();
            WriteApplicationDebugInfoToConsole();

            SetSystemKeyboardShortcuts();

            // Move to App??? app.SetupPluginSystem();
            SetupPluginSystem(); // This will Load the Core Plugin and all other, will either reference it as a dependancy or dont need it to be started first


            #endregion

            // check if we are the current user's shell
            // set here as well so that we don't behave differently once user changes setting
            IsCairoUserShell = Shell.IsCairoUserShell; // Move to CairoDesktop.Plugins.CairoShellCoreServices.... Make this more robust, to account for system-shell or per-user-shell;

            if (Settings.EnableDesktop)                // Future: This should be moved to whatever plugin is responsible for desktop stuff
            {
                // hide the windows desktop
                Shell.ToggleDesktopIcons(false);
            }

            App app = new App();
            app.InitializeComponent();  // This sets up the Unhandled Exception stuff...

            // Themes are very UI centric. We should devise a way of having Plugins/Extensions contribute to this.
            string theme = Settings.CairoTheme;
            if (theme != "Default")
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + theme))
                {
                    app.Resources.MergedDictionaries.Add((ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme)));
                }
            }

            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            if (Settings.EnableTaskbar)
            {
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarPos((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            MenuBarWindow  = new MenuBar(System.Windows.Forms.Screen.PrimaryScreen);
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();
            MenuBarWindows.Add(MenuBarWindow);

            // Future: This should be moved to whatever plugin is responsible for Desktop stuff
            if (Settings.EnableDesktop)
            {
                DesktopWindow = new Desktop();
                DesktopWindow.Show();
            }

            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            if (Settings.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow(MenuBarWindow, System.Windows.Forms.Screen.PrimaryScreen);
                MenuBarShadowWindow.Show();
                MenuBarShadowWindows.Add(MenuBarShadowWindow);
            }

            // Future: This should be moved to whatever plugin is responsible for Taskbar stuff
            if (Settings.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar(System.Windows.Forms.Screen.PrimaryScreen);
                TaskbarWindow.Show();
                TaskbarWindows.Add(TaskbarWindow);
            }

            // Future: This should be moved to whatever plugin is responsible for Taskbar/MennuBart stuff
            if (Settings.EnableMenuBarMultiMon || Settings.EnableTaskbarMultiMon)
            {
                ScreenSetup(true);
            }
            else if (IsCairoUserShell) // Set desktop work area for when Explorer isn't running
            {
                AppBarHelper.SetWorkArea(System.Windows.Forms.Screen.PrimaryScreen);
            }

            // Future: This should be moved to whatever plugin is responsible for SystemTray stuff. Possibly Core with no UI, then have a plugin that gives the UI?
            if (Settings.EnableSysTray == true)
            {
                NotificationArea.Instance.Initialize();
            }

#if ENABLEFIRSTRUN
            FirstRun();
#endif

            // login items only necessary if Explorer didn't start them
            if (IsCairoUserShell && !isRestart)
            {
                RunStartupApps();
            }

            app.Run();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Compares the system screen list to the screens associated with Cairo windows, then creates or destroys windows as necessary.
        /// Only affects non-primary screens, as Cairo always opens on at least the primary screen.
        /// Runs at startup and when a WM_DISPLAYCHANGE message is received by the main MenuBar window.
        /// </summary>
        public static void ScreenSetup(bool skipChecks = false)
        {
            lock (screenSetupLock)
            {
                CairoLogger.Instance.Debug("Beginning screen setup");
                IsSettingScreens = true;

                bool shouldSetScreens = true;

                List <string> sysScreens     = new List <string>();
                List <string> openScreens    = new List <string>();
                List <string> addedScreens   = new List <string>();
                List <string> removedScreens = new List <string>();

                ResetScreenCache();

                if (screenState.Length == System.Windows.Forms.Screen.AllScreens.Length)
                {
                    bool same = true;
                    for (int i = 0; i < screenState.Length; i++)
                    {
                        System.Windows.Forms.Screen current = System.Windows.Forms.Screen.AllScreens[i];
                        if (!(screenState[i].Bounds == current.Bounds && screenState[i].DeviceName == current.DeviceName && screenState[i].Primary == current.Primary && screenState[i].WorkingArea == current.WorkingArea))
                        {
                            same = false;
                            break;
                        }
                    }

                    if (same)
                    {
                        CairoLogger.Instance.Debug("Skipping screen setup due to no differences");
                        shouldSetScreens = false;
                    }
                    else
                    {
                        screenState = System.Windows.Forms.Screen.AllScreens;
                    }
                }
                else
                {
                    screenState = System.Windows.Forms.Screen.AllScreens;
                }

                if (shouldSetScreens)
                {
                    if (!skipChecks)
                    {
                        // enumerate screens

                        if (Settings.EnableMenuBarMultiMon || !Settings.EnableTaskbar)
                        {
                            foreach (MenuBar bar in MenuBarWindows)
                            {
                                if (bar.Screen != null)
                                {
                                    openScreens.Add(bar.Screen.DeviceName);
                                }
                            }
                        }
                        else if (Settings.EnableTaskbarMultiMon)
                        {
                            foreach (Taskbar bar in TaskbarWindows)
                            {
                                if (bar.Screen != null)
                                {
                                    openScreens.Add(bar.Screen.DeviceName);
                                }
                            }
                        }
                        else
                        {
                            return;
                        }

                        foreach (var screen in screenState)
                        {
                            CairoLogger.Instance.Debug(string.Format("{0} found at {1} with area {2}; primary? {3}", screen.DeviceName, screen.Bounds.ToString(), screen.WorkingArea.ToString(), screen.Primary.ToString()));

                            sysScreens.Add(screen.DeviceName);
                        }

                        // figure out which screens have been added vs removed

                        foreach (string name in sysScreens)
                        {
                            if (!openScreens.Contains(name))
                            {
                                addedScreens.Add(name);
                            }
                        }

                        foreach (string name in openScreens)
                        {
                            if (!sysScreens.Contains(name))
                            {
                                removedScreens.Add(name);
                            }
                        }

                        if (removedScreens.Count == sysScreens.Count)
                        {
                            // remove everything?! no way!
                            return;
                        }

                        // close windows associated with removed screens
                        foreach (string name in removedScreens)
                        {
                            CairoLogger.Instance.Debug("Removing windows associated with screen " + name);

                            // close taskbars
                            Taskbar taskbarToClose = null;
                            foreach (Taskbar bar in TaskbarWindows)
                            {
                                if (bar.Screen != null && bar.Screen.DeviceName == name)
                                {
                                    taskbarToClose = bar;
                                    break;
                                }
                            }

                            if (taskbarToClose != null)
                            {
                                taskbarToClose.Close();
                                TaskbarWindows.Remove(taskbarToClose);
                            }

                            // close menu bars
                            MenuBar barToClose = null;
                            foreach (MenuBar bar in MenuBarWindows)
                            {
                                if (bar.Screen != null && bar.Screen.DeviceName == name)
                                {
                                    CairoLogger.Instance.DebugIf(bar.Screen.Primary, "Closing menu bar on primary display");

                                    barToClose = bar;
                                    break;
                                }
                            }

                            if (barToClose != null)
                            {
                                if (!barToClose.IsClosing)
                                {
                                    barToClose.Close();
                                }
                                MenuBarWindows.Remove(barToClose);
                            }

                            // close menu bar shadows
                            MenuBarShadow barShadowToClose = null;
                            foreach (MenuBarShadow bar in MenuBarShadowWindows)
                            {
                                if (bar.Screen != null && bar.Screen.DeviceName == name)
                                {
                                    barShadowToClose = bar;
                                    break;
                                }
                            }

                            if (barShadowToClose != null)
                            {
                                if (!barShadowToClose.IsClosing)
                                {
                                    barShadowToClose.Close();
                                }
                                MenuBarShadowWindows.Remove(barShadowToClose);
                            }
                        }

                        CairoLogger.Instance.Debug("Refreshing screen information for stale windows");

                        // update screens of stale windows
                        foreach (MenuBar bar in MenuBarWindows)
                        {
                            if (bar.Screen != null)
                            {
                                foreach (System.Windows.Forms.Screen screen in screenState)
                                {
                                    if (screen.DeviceName == bar.Screen.DeviceName)
                                    {
                                        bar.Screen = screen;
                                        break;
                                    }
                                }
                            }
                        }

                        foreach (MenuBarShadow bar in MenuBarShadowWindows)
                        {
                            if (bar.Screen != null)
                            {
                                foreach (System.Windows.Forms.Screen screen in screenState)
                                {
                                    if (screen.DeviceName == bar.Screen.DeviceName)
                                    {
                                        bar.Screen = screen;
                                        break;
                                    }
                                }
                            }
                        }

                        foreach (Taskbar bar in TaskbarWindows)
                        {
                            if (bar.Screen != null)
                            {
                                foreach (System.Windows.Forms.Screen screen in screenState)
                                {
                                    if (screen.DeviceName == bar.Screen.DeviceName)
                                    {
                                        bar.Screen = screen;
                                        bar.setPosition();
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // open windows on newly added screens
                    foreach (var screen in screenState)
                    {
                        if ((skipChecks && !screen.Primary) || addedScreens.Contains(screen.DeviceName))
                        {
                            CairoLogger.Instance.Debug("Opening windows on screen " + screen.DeviceName);

                            if (Settings.EnableMenuBarMultiMon)
                            {
                                CairoLogger.Instance.DebugIf(screen.Primary, "Opening MenuBar on new primary display");

                                // menu bars
                                MenuBar newMenuBar = new MenuBar(screen);
                                newMenuBar.Show();
                                MenuBarWindows.Add(newMenuBar);

                                if (Settings.EnableMenuBarShadow)
                                {
                                    // menu bar shadows
                                    MenuBarShadow newMenuBarShadow = new MenuBarShadow(newMenuBar, screen);
                                    newMenuBarShadow.Show();
                                    MenuBarShadowWindows.Add(newMenuBarShadow);
                                }
                            }

                            if (Settings.EnableTaskbarMultiMon && Settings.EnableTaskbar)
                            {
                                // taskbars
                                Taskbar newTaskbar = new Taskbar(screen);
                                newTaskbar.Show();
                                TaskbarWindows.Add(newTaskbar);
                            }
                        }

                        // Set desktop work area for when Explorer isn't running
                        if (IsCairoUserShell)
                        {
                            AppBarHelper.SetWorkArea(screen);
                        }
                    }
                }

                IsSettingScreens = false;
                CairoLogger.Instance.Debug("Completed screen setup");
            }
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            #region Initialization Routines

            ProcessCommandLineArgs(args);
            if (!SingleInstanceCheck())
            {
                return;
            }
            SetShellReadyEvent();

            SetupSettings(); // run this before logging setup so that preferences are always used
            SetupLoggingSystem();
            WriteApplicationDebugInfoToConsole();

            SetSystemKeyboardShortcuts();

            // Move to App??? app.SetupPluginSystem();
            SetupPluginSystem(); // This will Load the Core Plugin and all other, will either reference it as a dependancy or dont need it to be started first


            #endregion

            // check if we are the current user's shell
            // set here as well so that we don't behave differently once user changes setting
            // First check if there is an existing Shell_TrayWnd. If so, then Explorer is actually running as shell so assume we are not.
            IntPtr taskbarHwnd = NativeMethods.FindWindow("Shell_TrayWnd", "");
            IsCairoRunningAsShell = Shell.IsCairoConfiguredAsShell && taskbarHwnd == IntPtr.Zero; // Move to CairoDesktop.Plugins.CairoShellCoreServices.... Make this more robust, to account for system-shell or per-user-shell;

            if (Settings.Instance.EnableDesktop)                                                  // Future: This should be moved to whatever plugin is responsible for desktop stuff
            {
                // hide the windows desktop
                Shell.ToggleDesktopIcons(false);
            }

            App app = new App();
            app.InitializeComponent();  // This sets up the Unhandled Exception stuff...

            // Themes are very UI centric. We should devise a way of having Plugins/Extensions contribute to this.
            string theme = Settings.Instance.CairoTheme;
            if (theme != "Default")
            {
                string themeFilePath = AppDomain.CurrentDomain.BaseDirectory + theme;
                if (System.IO.File.Exists(themeFilePath))
                {
                    ResourceDictionary newRes = new ResourceDictionary();
                    newRes.Source = new Uri(themeFilePath, UriKind.RelativeOrAbsolute);
                    app.Resources.MergedDictionaries.Add(newRes);
                }
            }

            Settings.Instance.PropertyChanged += (s, e) =>
            {
                if (e != null && !string.IsNullOrWhiteSpace(e.PropertyName) && e.PropertyName == "CairoTheme")
                {
                    App.Current.Resources.MergedDictionaries.Clear();
                    ResourceDictionary cairoResource = new ResourceDictionary();

                    // Put our base theme back
                    cairoResource.Source = new Uri("Cairo.xaml", UriKind.RelativeOrAbsolute);
                    App.Current.Resources.MergedDictionaries.Add(cairoResource);

                    string newTheme = Settings.Instance.CairoTheme;
                    if (newTheme != "Default")
                    {
                        string newThemeFilePath = AppDomain.CurrentDomain.BaseDirectory + newTheme;
                        if (System.IO.File.Exists(newThemeFilePath))
                        {
                            ResourceDictionary newRes = new ResourceDictionary();
                            newRes.Source = new Uri(newThemeFilePath, UriKind.RelativeOrAbsolute);
                            app.Resources.MergedDictionaries.Add(newRes);
                        }
                    }
                }
            };


            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            if (Settings.Instance.EnableTaskbar)
            {
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarPos((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            MenuBarWindow  = new MenuBar(System.Windows.Forms.Screen.PrimaryScreen);
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();
            MenuBarWindows.Add(MenuBarWindow);

            // Future: This should be moved to whatever plugin is responsible for Desktop stuff
            if (Settings.Instance.EnableDesktop)
            {
                DesktopWindow = new Desktop();
                DesktopWindow.Show();
            }

            // Future: This should be moved to whatever plugin is responsible for MenuBar stuff
            if (Settings.Instance.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow(MenuBarWindow, System.Windows.Forms.Screen.PrimaryScreen);
                MenuBarShadowWindow.Show();
                MenuBarShadowWindows.Add(MenuBarShadowWindow);
            }

            // Future: This should be moved to whatever plugin is responsible for Taskbar stuff
            if (Settings.Instance.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar(System.Windows.Forms.Screen.PrimaryScreen);
                TaskbarWindow.Show();
                TaskbarWindows.Add(TaskbarWindow);
            }

            // Future: This should be moved to whatever plugin is responsible for Taskbar/MennuBart stuff
            if (Settings.Instance.EnableMenuBarMultiMon || Settings.Instance.EnableTaskbarMultiMon)
            {
                ScreenSetup(true);
            }
            else if (IsCairoRunningAsShell) // Set desktop work area for when Explorer isn't running
            {
                AppBarHelper.SetWorkArea(System.Windows.Forms.Screen.PrimaryScreen);
            }

            // Future: This should be moved to whatever plugin is responsible for SystemTray stuff. Possibly Core with no UI, then have a plugin that gives the UI?
            // Don't allow showing both the Windows taskbar and the Cairo tray
            if (Settings.Instance.EnableSysTray == true && (Settings.Instance.EnableTaskbar == true || IsCairoRunningAsShell))
            {
                NotificationArea.Instance.Initialize();
            }

#if ENABLEFIRSTRUN
            FirstRun();
#endif

            // login items only necessary if Explorer didn't start them
            if (IsCairoRunningAsShell && !isRestart)
            {
                RunStartupApps();
            }

            app.Run();
        }
Ejemplo n.º 11
0
        public static void Main()
        {
            #region Single Instance Check
            bool ok;
            cairoMutex = new System.Threading.Mutex(true, "CairoShell", out ok);

            if (!ok)
            {
                // Another instance is already running.
                return;
            }
            #endregion

            #region some real shell code
            int hShellReadyEvent;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5)
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, true, @"Global\msgina: ShellReadyEvent");
            }
            else
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, false, "msgina: ShellReadyEvent");
            }

            if (hShellReadyEvent != 0)
            {
                NativeMethods.SetEvent(hShellReadyEvent);
                NativeMethods.CloseHandle(hShellReadyEvent);
            }
            #endregion

            #region old code
            //if (!SingleInstanceCheck())
            //{
            //    return;
            //}

            // Causes crash?
            // If framework is not correct version then quit.
            //if (!FrameworkCheck())
            //{
            //    return;
            //}
            #endregion

            InitializeParentWindow();

            App app = new App();

            MenuBarWindow = new MenuBar()
            {
                Owner = _parentWindow
            };
            MenuBarWindow.Show();
            app.MainWindow = MenuBarWindow;

#if (ENABLEFIRSTRUN)
            FirstRun(app);
#endif

            if (Properties.Settings.Default.EnableDesktop)
            {
                DesktopWindow = new Desktop()
                {
                    Owner = _parentWindow
                };
                DesktopWindow.Show();
                WindowInteropHelper f = new WindowInteropHelper(DesktopWindow);
                int result            = NativeMethods.SetShellWindow(f.Handle);
                DesktopWindow.ShowWindowBottomMost(f.Handle);
            }

            if (Properties.Settings.Default.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow()
                {
                    Owner = _parentWindow
                };
                MenuBarShadowWindow.Show();
            }

            if (Properties.Settings.Default.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar()
                {
                    Owner = _parentWindow
                };
                TaskbarWindow.Show();
            }

            app.Run();
        }
Ejemplo n.º 12
0
        public static void Main()
        {
            #region Single Instance Check
            bool ok;
            cairoMutex = new System.Threading.Mutex(true, "CairoShell", out ok);

            if (!ok)
            {
                // Another instance is already running.
                return;
            }
            #endregion

            #region some real shell code
            int hShellReadyEvent;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5)
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, true, @"Global\msgina: ShellReadyEvent");
            else
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, false, "msgina: ShellReadyEvent");

            if (hShellReadyEvent != 0)
            {
                NativeMethods.SetEvent(hShellReadyEvent);
                NativeMethods.CloseHandle(hShellReadyEvent);
            }
            #endregion

            #region old code
            //if (!SingleInstanceCheck())
            //{
            //    return;
            //}

            // Causes crash?
            // If framework is not correct version then quit.
            //if (!FrameworkCheck())
            //{
            //    return;
            //}
            #endregion

            InitializeParentWindow();

            App app = new App();

            MenuBarWindow = new MenuBar() { Owner = _parentWindow };
            MenuBarWindow.Show();
            app.MainWindow = MenuBarWindow;

            #if (ENABLEFIRSTRUN)
            FirstRun(app);
            #endif

            if (Properties.Settings.Default.EnableDesktop)
            {
                DesktopWindow = new Desktop() { Owner = _parentWindow };
                DesktopWindow.Show();
                WindowInteropHelper f = new WindowInteropHelper(DesktopWindow);
                int result = NativeMethods.SetShellWindow(f.Handle);
                DesktopWindow.ShowWindowBottomMost(f.Handle);
            }

            if (Properties.Settings.Default.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow() { Owner = _parentWindow };
                MenuBarShadowWindow.Show();
            }

            if (Properties.Settings.Default.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar() { Owner = _parentWindow };
                TaskbarWindow.Show();
            }

            app.Run();
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            if (args.Length > 0 && args[0] == "/restart")
            {
                isRestart = true;
            }
            else
            {
                isRestart = false;
            }

            #region Single Instance Check
            bool ok;
            cairoMutex = new System.Threading.Mutex(true, "CairoShell", out ok);

            if (!ok && !isRestart)
            {
                // Another instance is already running.
                return;
            }
            else if (!ok && isRestart)
            {
                // this is a restart so let's wait for the old instance to end
                System.Threading.Thread.Sleep(2000);
            }
            #endregion

            // Show a splash screen while WPF inits
            // not needed any more
            //SplashScreen splash = new SplashScreen("Resources/loadSplash.png");
            //splash.Show(false, true);

            #region some real shell code
            int hShellReadyEvent;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5)
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, true, @"Global\msgina: ShellReadyEvent");
            }
            else
            {
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, false, "msgina: ShellReadyEvent");
            }

            if (hShellReadyEvent != 0)
            {
                NativeMethods.SetEvent(hShellReadyEvent);
                NativeMethods.CloseHandle(hShellReadyEvent);
            }
            #endregion

            // check if we are the current user's shell
            object userShell = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", false).GetValue("Shell");
            procName = Process.GetCurrentProcess().ProcessName;
            if (userShell != null)
            {
                IsCairoUserShell = userShell.ToString().ToLower().Contains("cairodesktop");
            }
            else
            {
                IsCairoUserShell = false;
            }

            // Before we do anything, check if settings need to be upgraded
            if (Settings.IsFirstRun == true)
            {
                Settings.Upgrade();
            }

            if (Settings.EnableTaskbar)
            {
                // hide the windows taskbar according to user prefs
                switch (Settings.WindowsTaskbarMode)
                {
                case 0:
                    AppBarHelper.SetWinTaskbarPos(NativeMethods.SWP_HIDEWINDOW);
                    break;

                case 1:
                    AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                    break;

                case 2:
                    break;

                default:
                    break;
                }
            }

            if (Settings.EnableDesktop)
            {
                // hide the windows desktop
                Shell.ToggleDesktopIcons(false);
            }

            _parentWindow = new Window();
            InitializeParentWindow(_parentWindow);

            _desktopWindow = new Window();
            InitializeParentWindow(_desktopWindow);
            DeskParent = _desktopWindow;

            App app = new App();
            app.InitializeComponent();

            // Set custom theme if selected
            string theme = Settings.CairoTheme;
            if (theme != "Default")
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + theme))
                {
                    app.Resources.MergedDictionaries.Add((ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme)));
                }
            }

            // Set desktop work area for when Explorer isn't running
            if (IsCairoUserShell)
            {
                AppBarHelper.SetWorkArea();
            }

            MenuBarWindow = new MenuBar()
            {
                Owner = _parentWindow
            };
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();

            if (Settings.EnableDesktop)
            {
                DesktopWindow = new Desktop()
                {
                    Owner = _desktopWindow
                };
                DesktopWindow.Show();
            }

            if (Settings.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow()
                {
                    Owner = _desktopWindow
                };
                MenuBarShadowWindow.Show();
            }

            if (Settings.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar()
                {
                    Owner = _parentWindow
                };
                TaskbarWindow.Show();
            }

#if (ENABLEFIRSTRUN)
            FirstRun();
#endif

            // Close the splash screen
            //splash.Close(new TimeSpan(0, 0, 0, 0, 800));

            // login items only necessary if Explorer didn't start them
            if (IsCairoUserShell && !isRestart)
            {
                RunStartupApps();
            }

            app.Run();
        }
Ejemplo n.º 14
0
        public static void Main()
        {
            #region Single Instance Check
            bool ok;
            cairoMutex = new System.Threading.Mutex(true, "CairoShell", out ok);

            if (!ok)
            {
                // Another instance is already running.
                return;
            }
            #endregion

            // Show a splash screen while WPF inits
            SplashScreen splash = new SplashScreen("Resources/loadSplash.png");
            splash.Show(false, true);

            #region some real shell code
            int hShellReadyEvent;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5)
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, true, @"Global\msgina: ShellReadyEvent");
            else
                hShellReadyEvent = NativeMethods.OpenEvent(NativeMethods.EVENT_MODIFY_STATE, false, "msgina: ShellReadyEvent");

            if (hShellReadyEvent != 0)
            {
                NativeMethods.SetEvent(hShellReadyEvent);
                NativeMethods.CloseHandle(hShellReadyEvent);
            }
            #endregion

            // check if we are the current user's shell
            object userShell = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", false).GetValue("Shell");
            procName = Process.GetCurrentProcess().ProcessName;
            if (userShell != null)
                IsCairoUserShell = userShell.ToString().ToLower().Contains("cairodesktop");
            else
                IsCairoUserShell = false;

            // Before we do anything, check if settings need to be upgraded
            if (Properties.Settings.Default.IsFirstRun == true)
                Properties.Settings.Default.Upgrade();

            if (Properties.Settings.Default.EnableTaskbar)
            {
                // hide the windows taskbar
                SupportingClasses.AppBarHelper.SetWinTaskbarState(SupportingClasses.AppBarHelper.WinTaskbarState.AutoHide);
            }

            if (Properties.Settings.Default.EnableDesktop)
            {
                // hide the windows desktop
                Interop.Shell.ToggleDesktopIcons(false);
            }

            _parentWindow = new Window();
            InitializeParentWindow(_parentWindow);

            _desktopWindow = new Window();
            InitializeParentWindow(_desktopWindow);
            DeskParent = _desktopWindow;

            App app = new App();
            app.InitializeComponent();

            // Set custom theme if selected
            string theme = CairoDesktop.Properties.Settings.Default.CairoTheme;
            if (theme != "Default")
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + theme)) app.Resources.MergedDictionaries.Add((ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme)));

            MenuBarWindow = new MenuBar() { Owner = _parentWindow };
            app.MainWindow = MenuBarWindow;
            MenuBarWindow.Show();

            if (Properties.Settings.Default.EnableDesktop)
            {
                DesktopWindow = new Desktop() { Owner = _desktopWindow };
                DesktopWindow.Show();
            }

            if (Properties.Settings.Default.EnableMenuBarShadow)
            {
                MenuBarShadowWindow = new MenuBarShadow() { Owner = _desktopWindow };
                MenuBarShadowWindow.Show();
            }

            if (Properties.Settings.Default.EnableTaskbar)
            {
                TaskbarWindow = new Taskbar() { Owner = _parentWindow };
                TaskbarWindow.Show();
            }

            // Set desktop work area for when Explorer isn't running
            SupportingClasses.AppBarHelper.SetWorkArea();

            #if (ENABLEFIRSTRUN)
            FirstRun(app);
            #endif

            // If explorer isn't shell, run startup apps.
            if(IsCairoUserShell)
            {
                RunStartupApps();
            }

            // Close the splash screen
            splash.Close(new TimeSpan(0, 0, 0, 0, 800));

            app.Run();
        }