Exemplo n.º 1
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            CreateJumpList();
            ResetTicking();

            //if you want to handle to command line args on the first instance you may want it to go here
            //or in the app.xaml.cs
            //ProcessCommandLineArgs(SingleInstance<App>.CommandLineArgs);

            var currentScreen = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);

            var screenChanged = (currentScreen.WorkingArea.Height != Properties.Settings.Default.CurrentScreenHeight ||
                                 currentScreen.WorkingArea.Width != Properties.Settings.Default.CurrentScreenWidth);

            // default position only for first run or when screen size changes
            // position the clock at top / right, primary screen
            if (Properties.Settings.Default.IsFirstRun || screenChanged)
            {
                Left = SystemParameters.PrimaryScreenWidth - Width - 15.0;
                Top  = 0;
            }

            sysTrayIcon              = new System.Windows.Forms.NotifyIcon();
            sysTrayIcon.Text         = "YAPA";
            sysTrayIcon.Icon         = new System.Drawing.Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\pomoTray.ico"), 40, 40);
            sysTrayIcon.Visible      = false;
            sysTrayIcon.DoubleClick += SysTrayIcon_DoubleClick;

            sysTrayIcon.ContextMenu = new System.Windows.Forms.ContextMenu(CreateNotifyIconContextMenu());
        }
Exemplo n.º 2
0
        private void _window_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (_settings.UnclickablityType != UnclickablityType.MoveHorizontally &&
                _settings.UnclickablityType != UnclickablityType.MoveVertically)
            {
                return;
            }

            if (_engine.Phase != PomodoroPhase.Break && _engine.Phase != PomodoroPhase.Work)
            {
                return;
            }

            var screen = GDIScreen.FromHandle(_app.WindowHandle);

            if (_settings.UnclickablityType == UnclickablityType.MoveHorizontally)
            {
                var appCenter         = _window.Left - screen.Bounds.X;
                var relativePossition = 1 - appCenter / (screen.Bounds.Width - _window.Width / 2);

                var newPossition = relativePossition * (screen.Bounds.Width - _window.Width / 2);

                _window.Left = newPossition + screen.Bounds.X;
            }
            else if (_settings.UnclickablityType == UnclickablityType.MoveVertically)
            {
                var appCenter         = _window.Top - screen.Bounds.Y;
                var relativePossition = 1 - appCenter / (screen.Bounds.Height - _window.Height / 2);

                var newPossition = relativePossition * (screen.Bounds.Height - _window.Height / 2);

                _window.Top = newPossition + screen.Bounds.Y;
            }
        }
Exemplo n.º 3
0
        public static WpfScreen GetScreenFrom(Window window)
        {
            var windowInteropHelper = new WindowInteropHelper(window);
            var display             = Display.FromHandle(windowInteropHelper.Handle);

            return(new WpfScreen(display));
        }
Exemplo n.º 4
0
        private void GetMainWindowPosAndSaveSettings()
        {
            GDIScreen currentScreen = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);

            Properties.Settings.Default.CurrentScreenHeight = currentScreen.WorkingArea.Height;
            Properties.Settings.Default.CurrentScreenWidth  = currentScreen.WorkingArea.Width;

            Properties.Settings.Default.Save();
        }
        private void App_Closing()
        {
            var currentScreen = GDIScreen.FromHandle(_app.WindowHandle);

            _settings.ActiveMonitor = currentScreen.DeviceName;

            var top  = _app.Top - currentScreen.Bounds.Top;
            var left = _app.Left - currentScreen.Bounds.Left;

            _settings.WindowTopPerc  = top / currentScreen.WorkingArea.Height;
            _settings.WindowLeftPerc = left / currentScreen.WorkingArea.Width;
        }
Exemplo n.º 6
0
        void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            if (Properties.Settings.Default.IsFirstRun)
            {
                Properties.Settings.Default.IsFirstRun = false;
            }

            GDIScreen currentScreen = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);

            Properties.Settings.Default.CurrentScreenHeight = currentScreen.WorkingArea.Height;
            Properties.Settings.Default.CurrentScreenWidth  = currentScreen.WorkingArea.Width;

            Properties.Settings.Default.Save();
        }
Exemplo n.º 7
0
        public Bitmap PrintWindow(IntPtr hwnd)
        {
            RECT rc;

            GetWindowRect(hwnd, out rc);

            Bitmap bmp = new Bitmap(rc.Right - rc.Left, rc.Bottom - rc.Top, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            //Bitmap bmp = new Bitmap((int)Width, (int)Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics gfxBmp    = Graphics.FromImage(bmp);
            IntPtr   hdcBitmap = gfxBmp.GetHdc();
            bool     succeeded = PrintWindow(hwnd, hdcBitmap, 0);

            gfxBmp.ReleaseHdc(hdcBitmap);
            if (!succeeded)
            {
                gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(System.Drawing.Point.Empty, bmp.Size));
            }
            IntPtr hRgn = CreateRectRgn(0, 0, 0, 0);

            GetWindowRgn(hwnd, hRgn);
            Region region = Region.FromHrgn(hRgn);

            if (!region.IsEmpty(gfxBmp))
            {
                gfxBmp.ExcludeClip(region);
                gfxBmp.Clear(System.Drawing.Color.Transparent);
            }

            gfxBmp.Dispose();

            //Crop image
            var      screen        = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);
            Bitmap   bmpFullScreen = new Bitmap(screen.WorkingArea.Width, screen.WorkingArea.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g             = Graphics.FromImage(bmpFullScreen);

            //Crop if image was bigger than screen
            var cropped = bmp.Clone(
                new System.Drawing.Rectangle(0, 0, Math.Min(screen.WorkingArea.Height, rc.Right - rc.Left),
                                             Math.Min(screen.WorkingArea.Width, rc.Bottom - rc.Top)), bmp.PixelFormat);

            g.DrawImage(cropped, new System.Drawing.Point(rc.Left, rc.Top));
            g.Dispose();

            //10 for border
            var result = bmpFullScreen.Clone(new System.Drawing.Rectangle((int)Left + 10, (int)Top + 10, (int)Width - 10, (int)Height - 10), bmpFullScreen.PixelFormat);

            return(result);
        }
Exemplo n.º 8
0
        private Screen GetScreen()
        {
            ManagedCommon.StartupPosition position = _settings.StartupPosition;
            switch (position)
            {
            case ManagedCommon.StartupPosition.PrimaryMonitor:
                return(Screen.PrimaryScreen);

            case ManagedCommon.StartupPosition.Focus:
                IntPtr foregroundWindowHandle = NativeMethods.GetForegroundWindow();
                Screen activeScreen           = Screen.FromHandle(foregroundWindowHandle);
                return(activeScreen);

            case ManagedCommon.StartupPosition.Cursor:
            default:
                return(Screen.FromPoint(System.Windows.Forms.Cursor.Position));
            }
        }
        private static double ComputeListBoxMaxWidth([NotNull] ListBox listBox, [CanBeNull] IContextBoundSettingsStore settings)
        {
            if (settings == null || !settings.GetValue((DisplaySettings s) => s.LimitTooltipWidth))
            {
                return(Double.PositiveInfinity);
            }

            var hwndSource = PresentationSource.FromVisual(listBox) as HwndSource;

            if (hwndSource == null)
            {
                return(Double.PositiveInfinity);
            }

            int    limitPercent = settings.GetValue((DisplaySettings s) => s.ScreenWidthLimitPercent).Clamp(10, 100);
            Screen screen       = Screen.FromHandle(hwndSource.Handle);

            return(screen.Bounds.Width * (limitPercent / 100.0) / DpiUtil.DpiHorizontalFactor);
        }
Exemplo n.º 10
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            CreateJumpList();

            //if you want to handle to command line args on the first instance you may want it to go here
            //or in the app.xaml.cs
            //ProcessCommandLineArgs(SingleInstance<App>.CommandLineArgs);

            GDIScreen currentScreen = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);

            bool screenChanged = (currentScreen.WorkingArea.Height != YAPA.Properties.Settings.Default.CurrentScreenHeight ||
                                  currentScreen.WorkingArea.Width != YAPA.Properties.Settings.Default.CurrentScreenWidth);

            // default position only for first run or when screen size changes
            // position the clock at top / right, primary screen
            if (YAPA.Properties.Settings.Default.IsFirstRun || screenChanged)
            {
                this.Left = SystemParameters.PrimaryScreenWidth - this.Width - 15.0;
                this.Top  = 0;
            }
        }
        private GDIScreen GetActiveScreen()
        {
            var activeScreen = GDIScreen.AllScreens.FirstOrDefault(x => string.Equals(x.DeviceName, _settings.ActiveMonitor));

            return(activeScreen ?? GDIScreen.FromHandle(_app.WindowHandle));
        }