Ejemplo n.º 1
0
        public bool IsBlackTarget(IntPtr hwnd)
        {
            var title = ThreadWindowHandles.GetWindowText(hwnd);

            if (title == string.Empty)
            {
                return(true);
            }
            return(HasTarget(IgnoreTargetList, hwnd));
        }
Ejemplo n.º 2
0
        public bool MatchRule(IntPtr hwnd)
        {
            var title     = ThreadWindowHandles.GetWindowText(hwnd);
            var className = ThreadWindowHandles.GetClassText(hwnd);

            if (WindowName.Contains(title))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 bool Scan( IntPtr hwnd , IntPtr lParam )
 {
     TileMode tileMode = IsManageable( hwnd );
     if ( tileMode != TileMode.NoHandle )
     {
         Manage( hwnd , tileMode );
         // chrome、最小化してるウィンドウがマスターだとサイズが0のように処理される
         ThreadWindowHandles.ShowWindow( hwnd , ThreadWindowHandles.SW.SW_RESTORE );
     }
     return true;
 }
Ejemplo n.º 4
0
 private static Client CreateClient( IntPtr hwnd )
 {
     var title = ThreadWindowHandles.GetWindowText( hwnd );
     if ( title == string.Empty )
     {
         title = ThreadWindowHandles.GetClassText( hwnd );
     }
     Client client = Types.createClient(
         hwnd , ThreadWindowHandles.GetParent( hwnd ) ,
         ( int )User32Methods.GetWindowThreadProcessId( hwnd , IntPtr.Zero ) ,
          WindowStyle( hwnd ) , title );
     return client;
 }
Ejemplo n.º 5
0
        private void OtherWindow( System.Windows.Forms.Message m , WM param , Client client )
        {
            //Trace.WriteLine( client?.Title + " " + param );
            switch ( param )
            {
                case WM.HSHELL_WINDOWCREATED:
                    TileMode tileMode = IsManageable( m.LParam );
                    if ( tileMode == TileMode.Tile )
                    {
                        var newClient = Manage( m.LParam , tileMode );
                        // とりあえず子ウィンドウはスルー
                        WindowManager.Tile( );
                    }
                    Trace.WriteLine( "created :" + ThreadWindowHandles.GetWindowText( m.LParam ) );

                    break;
                case WM.HSHELL_WINDOWDESTROYED:
                    if ( client != null )
                    {

                        Trace.WriteLine( "destroyed : " + ThreadWindowHandles.GetWindowText( m.LParam ) );
                        // タグ移動で隠された時にも来るので、その場合無視
                        if ( !client.Ignore )
                        {

                            Unmanage( client );
                            WindowManager.Tile( );
                        }
                        else
                        {
                            client.Ignore = false;
                        }
                    }
                    break;
                case WM.HSHELL_WINDOWACTIVATED:
                case WM.HSHELL_RUDEAPPACTIVATED:
                    if ( client != null )
                    {
                        WindowManager.ActiveClient = client;
                        Trace.WriteLine( "active : " + ThreadWindowHandles.GetWindowText( m.LParam ) );
                    }
                    break;

                default:
                    break;
            }

        }
Ejemplo n.º 6
0
        private static bool HasTarget(List <string> list, IntPtr hwnd)
        {
            var title     = ThreadWindowHandles.GetWindowText(hwnd);
            var classText = ThreadWindowHandles.GetClassText(hwnd);

            foreach (var item in list)
            {
                bool titleCont = title.Contains(item);
                bool classCont = classText.Contains(item);
                if (titleCont || classCont)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        // タイル化対象
        public bool IsTilingTarget(IntPtr hwnd)
        {
            var title     = ThreadWindowHandles.GetWindowText(hwnd);
            var classText = ThreadWindowHandles.GetClassText(hwnd);

            // 一部分で
            foreach (var item in NoTilingList)
            {
                bool titleCont = title.Contains(item);
                bool classCont = classText.Contains(item);
                if (titleCont || classCont)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 8
0
        private void QuitWindowManager( )
        {
            List<string> TitleAndClass = new List<string>();
            foreach ( var screen in WindowManager.ScreenList )
            {
                foreach ( var tagMan in screen.TagList )
                {
                    foreach ( var client in tagMan.ClientList )
                    {

                        var hwnd = client.Hwnd;
                        var title = ThreadWindowHandles.GetWindowText( hwnd );
                        var klass = ThreadWindowHandles.GetClassText( hwnd );
                        TitleAndClass.Add( "title : " + title + " class : " + klass );
                    }
                    //tagMan.DumpIcon( );
                }
            }
            System.IO.File.WriteAllLines( "dumpedTitleAndClass.txt" , TitleAndClass.ToArray( ) );
            CleanUp( );
            Close( );
        }
Ejemplo n.º 9
0
        void UpdateGeom( )
        {
            var hwnd = ThreadWindowHandles.FindWindow( "Shell_TrayWnd" , null );
            RECT rect = new RECT();

            if ( User32Methods.IsWindowVisible( hwnd )  )
            {
                ThreadWindowHandles.SystemParametersInfoGet( ( uint )SystemParametersDesktopInfo.SPI_GETWORKAREA , 0 ,
                    ref rect , ( uint )SystemParamtersInfoFlags.None );
                ScreenGeom = rect;
            }
            else
            {
                int sx = User32Methods.GetSystemMetrics( SystemMetrics.SM_XVIRTUALSCREEN );
                int sy = User32Methods.GetSystemMetrics( SystemMetrics.SM_YVIRTUALSCREEN );
                int sw = User32Methods.GetSystemMetrics( SystemMetrics.SM_CXVIRTUALSCREEN );
                int sh = User32Methods.GetSystemMetrics( SystemMetrics.SM_CYVIRTUALSCREEN );
                ScreenGeom = new RECT( sx , sy , sw , sh );
            }
            // 固定値
            BarHeight = 20;
            int wy = ScreenGeom.Top;
            int wh = ScreenGeom.Height;
            BarY = -BarHeight;
            {
                if ( TopBar )
                {
                    wy = ScreenGeom.Top + BarHeight;
                    BarY = wy - BarHeight;
                }
                else
                {
                    BarY = wy + wh;
                }
                wh = ScreenGeom.Height - BarHeight;
            }
            // ここ全体 TileWindowManagerに持っていきたい
            WindowManager.ScreenGeom = ScreenGeom;
        }
Ejemplo n.º 10
0
        TileMode IsManageable( IntPtr hwnd )
        {
            if ( ContainClient( hwnd ) )
            {
                return TileMode.NoHandle;
            }
            if ( hwnd == Handle )
            {
                return TileMode.NoHandle;
            }
            String windowText = ThreadWindowHandles.GetWindowText( hwnd );
            String classText = ThreadWindowHandles.GetClassText( hwnd );
            bool isFloatListName = false;
            if ( !_TileSetting.IsTilingTarget( hwnd ) )
            {
                isFloatListName = true;
            }
            if ( _TileSetting.IsBlackTarget( hwnd ) )
            {
                return TileMode.NoHandle;
            }
            Trace.WriteLine( windowText + " : className = " + classText );
#if RECOVER
            if ( 
                windowText.Contains( "Chrome" ) ||
                windowText.Contains( "Avast Secure" ) ||
                windowText.Contains( "Visual" ) ||
                windowText.Contains( "VIM" ) ||
                classText.Contains( "CabinetWClass" ) ||
                windowText.Contains("pmx") ||
                windowText.Contains("Blender")
                )
            {
                DWM.setVisibility( hwnd , true );
                return TileMode.Tile;
            }
#endif
            if ( User32Methods.GetWindowPlacement( hwnd , out WindowPlacement windowPlacement ) )
            {
                if ( ( windowPlacement.ShowCmd & ShowWindowCommands.SW_HIDE ) != 0 )
                {
                    return TileMode.NoHandle;
                }
            }

            var parent = ThreadWindowHandles.GetParent( hwnd );
            var owner = User32Helpers.GetWindow( hwnd , GetWindowFlag.GW_OWNER );
            WindowStyles style = WindowStyle( hwnd );
            //tosafeがほしいけど別ライブラリ内
            var exStyle = ( WindowExStyles )( User32Helpers.GetWindowLongPtr( hwnd , WindowLongFlags.GWL_EXSTYLE ).ToInt32( ) );
            bool isParentOK = parent != IntPtr.Zero && IsManageable( parent ) == TileMode.Tile;
            bool isTool = ( exStyle & WindowExStyles.WS_EX_TOOLWINDOW ) != 0;
            bool isApp = ( exStyle & WindowExStyles.WS_EX_APPWINDOW ) != 0;
            if ( isParentOK && !ContainClient( parent ) )
            {
                // なんか見えないウィンドウをmanageするので
                //Manage( hwnd );
            }

            if ( ( style & WindowStyles.WS_DISABLED ) != 0 )
            {
                return TileMode.NoHandle;
            }
            // WS_POPUPWINDOW も含んでいる
            if ( ( style & WindowStyles.WS_POPUP ) != 0 )
            {
                return TileMode.NoHandle;
            }
            bool hasParent = parent != IntPtr.Zero;
            var winIsVisibleAndNoParent = !hasParent && User32Methods.IsWindowVisible( hwnd );
            if ( winIsVisibleAndNoParent || isParentOK )
            {
                if ( ( !isTool && !hasParent ) || ( isTool && isParentOK ) || ( isApp && hasParent ) )
                {
                    if ( windowText != null )
                    {

                        Trace.Write( windowText );
                        Trace.WriteLine( " isTool : " + isTool + " isApp : " + isApp + " style : " + style );
                    }
                    if ( isFloatListName )
                    {
                        return TileMode.Float;
                    }
                    return TileMode.Tile;
                }
            }
            return TileMode.NoHandle;
        }
Ejemplo n.º 11
0
        public Form1( )
        {
            Logger = new DebugLogger( "Form1" );
            //foreach(var proc in Process.GetProcesses())
            //{
            //    var pname = proc.ProcessName;
            //    if(pname.Contains("Browser"))
            //    {
            //        Trace.WriteLine( pname );
            //        proc.Kill( );
            //    }
            //}
            _TileSetting = TileSetting.Load( SettingPath );

            WindowManager = new TileWindowManager( UIHeight );
            WindowManager.OnTagChange += ( s , e ) => Invalidate( );
            try
            {
                InitializeComponent( );

                ClientTitleList = new List<ListBox>( )
                {
                    listBox1,
                    listBox2,
                    listBox3,
                    listBox4,
                    listBox5,
                    listBox6,
                    listBox7,
                    listBox8,
                    listBox9,
                    listBox10,
                    listBox11,
                    listBox12,
                };

                for ( int i = 1 ; i < 10; i++ )
                {
                    Keys d0 = ( Keys )( ( int )Keys.D0 + i );
                    AddIndexHotKey( i , d0 );


                }
                AddIndexHotKey( 10 , Keys.D0 );
                AddIndexHotKey( 11 , Keys.OemMinus );
                // HHKBの^キー
                AddIndexHotKey( 12 , Keys.OemQuotes);

                HotkeyList.Add( new HotKey( Handle , ToggleHotID , Keys.H , Keys.Control ) );
                HotkeyList.Add( new HotKey( Handle , SortMaster , Keys.M , Keys.Control | Keys.Alt ) );
                HotkeyList.Add( new HotKey( Handle , QuitHotID , Keys.Q , Keys.Control | Keys.Alt ) );

                SetUp( );
                WindowManager.ActiveClient = WindowManager.TryGetMaster( );
                UpdateGeom( );
                ThreadWindowHandles.RegisterShellHookWindow( Handle );
                ShellHookID = ThreadWindowHandles.RegisterWindowMessage( "SHELLHOOK" );
                FormClosing += Form1_FormClosing;
                Bounds = ScreenGeom.Rect;
                Height = UIHeight;

                UpdateTimer = new Timer( );
                UpdateTimer.Interval = 10;
                UpdateTimer.Tick += T_Tick;
                UpdateTimer.Start( );
                Paint += Form1_Paint;
                // 狭いスクリーンだとquitがなくなることがある
                var widestScr = Screen.AllScreens.OrderBy( s => s.WorkingArea.Width ).Last( );
                Location = widestScr.Bounds.Location;
                WindowManager.BelongScreen = Screen.FromHandle( Handle );
                WindowManager.Tile( );
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.ToString( ) );
                CleanUp( );
            }
        }