Xamarin.MacでCGSDebugを使う

提供: MonoBook
移動: 案内検索
  • macOS 10.11 (El Capitan)以降では動かない模様(落ちたりはしないが常にNoneになる)。
  • macOS 10.12 (Sierra)でも動かない。
  • macOS 10.13 (High Sierra)は試していないが99%ダメだろう。
    using System;
    using System.Runtime.InteropServices;
    using AppKit;
 
    [Flags]
    public enum CGSDebugOption : uint
    {
        /// <summary>
        /// Clears all flags.
        /// </summary>
        None = 0,
 
        /// <summary>
        /// All screen updates are flashed in yellow. Regions under a DisableUpdate are flashed in orange. 
        /// Regions that are hardware accellerated are painted green.
        /// </summary>
        FlashScreenUpdates = 0x4,
 
        /// <summary>
        /// Colors windows green if they are accellerated, otherwise red. 
        /// Doesn't cause things to refresh properly - leaves excess rects cluttering the screen.
        /// </summary>
        ColorByAccelleration = 0x20,
 
        /// <summary>
        /// Disables shadows on all windows.
        /// </summary>
        NoShadows = 0x4000,
 
        /// <summary>
        /// Setting this disables the pause after a flash when using FlashScreenUpdates or FlashIdenticalUpdates.
        /// </summary>
        NoDelayAfterFlash = 0x20000,
 
        /// <summary>
        /// Flushes the contents to the screen after every drawing operation.
        /// </summary>
        AutoflushDrawing = 0x40000,
 
        /// <summary>
        /// mouse tracking areas. 
        /// Doesn't cause things to refresh correctly - leaves excess rectangles cluttering the screen.
        /// </summary>
        ShowMouseTrackingAreas = 0x100000,
 
        /// <summary>
        /// Flashes identical updates in red.
        /// </summary>
        FlashIdenticalUpdates = 0x4000000,
 
        /// <summary>
        /// Dumps a list of windows to /tmp/WindowServer.winfo.out. 
        /// This is what Quartz Debug uses to get the window list.
        /// </summary>
        DumpWindowListToFile = 0x80000001,
 
        /*! Dumps a list of connections to /tmp/WindowServer.cinfo.out. */
        DumpConnectionListToFile = 0x80000002,
 
        /*! Dumps a very verbose debug log of the WindowServer to /tmp/CGLog_WinServer_<PID>. */
        VerboseLogging = 0x80000006,
 
        /// <summary>
        /// Dumps a very verbose debug log of all processes to /tmp/CGLog_<NAME>_<PID>.
        /// </summary>
        VerboseLoggingAllApps = 0x80000007,
 
        /* > 7 seems like more logging options, perhaps with different verbosity or category */
 
        /// <summary>
        /// Dumps a list of hotkeys to /tmp/WindowServer.keyinfo.out.
        /// </summary>
        DumpHotKeyListToFile = 0x8000000E,
 
        /// <summary>
        /// Dumps a of surfaces to WindowServer.sinfo.out.
        /// </summary>
        DumpSurfacesToFile = 0x80000010,
 
        /// <summary>
        /// Dumps information about OpenGL extensions, etc to /tmp/WindowServer.glinfo.out.
        /// </summary>
        DumpOpenGLInfoToFile = 0x80000013,
 
        /// <summary>
        /// Dumps a list of shadows to /tmp/WindowServer.shinfo.out.
        /// </summary>
        DumpShadowListToFile = 0x80000014,
 
        /// <summary>
        /// Leopard: Dumps information about caches to `/tmp/WindowServer.scinfo.out`.
        /// </summary>
        DumpCacheInformationToFile = 0x80000015,
 
        /// <summary>
        /// Leopard: Purges some sort of cache - most likely the same caches dummped with `DumpCacheInformationToFile`.
        /// </summary>
        PurgeCaches = 0x80000016,
 
        /// <summary>
        /// Leopard: Dumps a list of windows to `/tmp/WindowServer.winfo.plist`. This is what Quartz Debug on 10.5 uses to get the window list.
        /// </summary>
        DumpWindowListToPlist = 0x80000017,
 
        /// <summary>
        /// Leopard: DOCUMENTATION PENDING
        /// </summary>
        EnableSurfacePurging = 0x8000001B,
 
        // Leopard: 0x8000001C - invalid
 
        /// <summary>
        /// Leopard: DOCUMENTATION PENDING
        /// </summary>
        DisableSurfacePurging = 0x8000001D,
 
        /// <summary>
        /// Leopard: Dumps information about an application's resource usage to `/tmp/CGResources_<NAME>_<PID>`.
        /// </summary>
        DumpResourceUsageToFiles = 0x80000020,
 
        // Leopard: 0x80000022 - something about QuartzGL?
 
        /// <summary>
        /// Leopard: Returns the magic mirror to its normal mode. 
        /// The magic mirror is what the Dock uses to draw the screen reflection. 
        /// For more information, see `CGSSetMagicMirror`. */
        /// </summary>
        SetMagicMirrorModeNormal = 0x80000023,
 
        /// <summary>
        /// Leopard: Disables the magic mirror. It still appears but draws black instead of a reflection.
        /// </summary>
        SetMagicMirrorModeDisabled = 0x80000024,
 
        /// <summary>
        /// Snow Leopard:
        /// </summary>
        DumpColorProfileInfoToFile = 0x80000029,
 
        /// <summary>
        /// Snow Leopard:
        /// </summary>
        DumpShmemInfoToFile = 0x8000002c
 
    }
 
 
    static class MainClass
    {
        [DllImport("/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/CoreGraphics")]
        static extern int CGSGetDebugOptions(out CGSDebugOption options);
 
        [DllImport("/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/CoreGraphics")]
        static extern int CGSSetDebugOptions(CGSDebugOption options);
 
        static void Main(string[] args)
        {
            NSApplication.Init();
 
            // フラグ取得
            CGSDebugOption option;
            CGSGetDebugOptions(out option);
            Console.WriteLine("old: " + option);
 
            // フラグ反転
            option = option ^ CGSDebugOption.NoShadows;
            CGSSetDebugOptions(option);
            Console.WriteLine("new: " + option);
        }
    }