//TODO: only get the extension if we actually need a new Xid alloc public XidManager(XCMisc xcmisc) { this.xcmisc = xcmisc; c = xcmisc.Connection; last = 0; idbase = c.Setup.ResourceIdBase; max = c.Setup.ResourceIdMask; inc = (uint)(c.Setup.ResourceIdMask & -(c.Setup.ResourceIdMask)); }
//TODO: only get the extension if we actually need a new Xid alloc public XidManager (XCMisc xcmisc) { this.xcmisc = xcmisc; c = xcmisc.Connection; last = 0; idbase = c.Setup.ResourceIdBase; max = c.Setup.ResourceIdMask; inc = (uint) (c.Setup.ResourceIdMask & -(c.Setup.ResourceIdMask)); }
public static void Main(string[] args) { if (args.Length != 3) { Console.Error.WriteLine("Usage: testsimple [depth] [root] [visual]"); return; } Connection c = new Connection(null, 0); //Connection c = new Connection ("localhost", 0); Console.WriteLine("Release: " + c.Setup.ReleaseNumber); Console.WriteLine("Vendor: " + c.Setup.Vendor); Console.WriteLine("VendorLen: " + c.Setup.VendorLen); Console.WriteLine("RootsLen: " + c.Setup.RootsLen); Console.WriteLine("PixmapFormatsLen: " + c.Setup.PixmapFormatsLen); /* * Screen root; * int screen_num = 0; * root = Aux.GetScreen (c, screen_num); * int depth = 1; * Console.WriteLine (root); * Console.WriteLine (root.Root); * Console.WriteLine (root.WhitePixel); * Console.WriteLine (root.WidthInPixels); * Console.WriteLine (root.HeightInPixels); */ XCMisc xcmisc = new XCMisc(); xcmisc.Init(c); /* * XFixes xfixes = new XFixes (); * xfixes.Init (c); */ XidManager xm = new XidManager(xcmisc); XProto xp = new XProto(); xp.Init(c); WindowId wid = (WindowId)xm.Generate(); Console.WriteLine("New xid: " + (uint)wid); //use xdpyinfo to find root window id WindowId parentId = new WindowId((uint)Int32.Parse(args[1], System.Globalization.NumberStyles.HexNumber)); //use xdpyinfo to find a visual //uint visualId = 0x23; uint visualId = (uint)Int32.Parse(args[2], System.Globalization.NumberStyles.HexNumber); //byte depth = 16; byte depth = (byte)Int32.Parse(args[0]); uint[] flags = new uint[4]; //Mask flags[0] = (uint)(WindowValueMask.BackgroundPixel | WindowValueMask.EventMask | WindowValueMask.DoNotPropagateMask); //flags[0] = (uint) (Cw.BackPixel | Cw.EventMask | Cw.DontPropagate); //flags[0] = 0x00000100 | 0x00000800 | 0x00001000; //BackgroundPixel flags[1] = 0xffff0000; //EventMask //flags[2] = (uint) (EventMask.ButtonReleaseMask | EventMask.ExposureMask); flags[2] = 0x00000008 | 0x00008000; //DoNotPropagateMask //flags[3] = (uint) (EventMask.ButtonPressMask); flags[3] = 0x00000004; xp.CreateWindow(depth, wid, parentId, 10, 10, 100, 100, 0, (ushort)WindowClass.InputOutput, visualId, flags); xp.ChangeProperty((byte)PropertyMode.Replace, wid, AtomType.WM_NAME, AtomType.STRING, 8, 0); xp.MapWindow(wid); PixmapId pid = (PixmapId)xm.Generate(); xp.CreatePixmap(depth, pid, wid, 100, 100); Rectangle rect = new Rectangle(); rect.X = 0; rect.Y = 0; rect.Width = 100; rect.Height = 100; Rectangle[] rects = new Rectangle[1]; rects[0] = rect; //xc.PolyFillRectangle (pid, whitegc, rects); xp.ClearArea(false, wid, 10, 10, 20, 20); //Sync: //xp.GetInputFocus (); while (true) { c.xrr.ReadMessage(); } }
public static void Main (string[] args) { if (args.Length != 3) { Console.Error.WriteLine ("Usage: testsimple [depth] [root] [visual]"); return; } Connection c = new Connection (null, 0); //Connection c = new Connection ("localhost", 0); Console.WriteLine ("Release: " + c.Setup.ReleaseNumber); Console.WriteLine ("Vendor: " + c.Setup.Vendor); Console.WriteLine ("VendorLen: " + c.Setup.VendorLen); Console.WriteLine ("RootsLen: " + c.Setup.RootsLen); Console.WriteLine ("PixmapFormatsLen: " + c.Setup.PixmapFormatsLen); /* Screen root; int screen_num = 0; root = Aux.GetScreen (c, screen_num); int depth = 1; Console.WriteLine (root); Console.WriteLine (root.Root); Console.WriteLine (root.WhitePixel); Console.WriteLine (root.WidthInPixels); Console.WriteLine (root.HeightInPixels); */ XCMisc xcmisc = new XCMisc (); xcmisc.Init (c); /* XFixes xfixes = new XFixes (); xfixes.Init (c); */ XidManager xm = new XidManager (xcmisc); XProto xp = new XProto (); xp.Init (c); WindowId wid = (WindowId)xm.Generate (); Console.WriteLine ("New xid: " + (uint)wid); //use xdpyinfo to find root window id WindowId parentId = new WindowId ((uint)Int32.Parse (args[1], System.Globalization.NumberStyles.HexNumber)); //use xdpyinfo to find a visual //uint visualId = 0x23; uint visualId = (uint)Int32.Parse (args[2], System.Globalization.NumberStyles.HexNumber); //byte depth = 16; byte depth = (byte)Int32.Parse (args[0]); uint[] flags = new uint[4]; //Mask flags[0] = (uint) (WindowValueMask.BackgroundPixel | WindowValueMask.EventMask | WindowValueMask.DoNotPropagateMask); //flags[0] = (uint) (Cw.BackPixel | Cw.EventMask | Cw.DontPropagate); //flags[0] = 0x00000100 | 0x00000800 | 0x00001000; //BackgroundPixel flags[1] = 0xffff0000; //EventMask //flags[2] = (uint) (EventMask.ButtonReleaseMask | EventMask.ExposureMask); flags[2] = 0x00000008 | 0x00008000; //DoNotPropagateMask //flags[3] = (uint) (EventMask.ButtonPressMask); flags[3] = 0x00000004; xp.CreateWindow (depth, wid, parentId, 10, 10, 100, 100, 0, (ushort)WindowClass.InputOutput, visualId, flags); xp.ChangeProperty ((byte)PropertyMode.Replace, wid, AtomType.WM_NAME, AtomType.STRING, 8, 0); xp.MapWindow (wid); PixmapId pid = (PixmapId)xm.Generate (); xp.CreatePixmap (depth, pid, wid, 100, 100); Rectangle rect = new Rectangle (); rect.X = 0; rect.Y = 0; rect.Width = 100; rect.Height = 100; Rectangle[] rects = new Rectangle[1]; rects[0] = rect; //xc.PolyFillRectangle (pid, whitegc, rects); xp.ClearArea (false, wid, 10, 10, 20, 20); //Sync: //xp.GetInputFocus (); while (true) { c.xrr.ReadMessage (); } }
public int allocate_id(Object obj) { /* From XC-MISC extension specification: * * When an X client connects to an X server, it receives a fixed range * of resource IDs to use to identify the client's resources inside the * X server. Xlib hands these out sequentially as needed. When it * overruns the end of the range, an IDChoice protocol error results. * Long running clients, or clients that use resource IDs at a rapid * rate, may encounter this circumstance. When it happens, there are * usually many resource IDs available, but Xlib doesn't know about * them. * * One approach to solving this problem would be to have Xlib notice * when a resource is freed and recycle its ID for future use. This * strategy runs into difficulties because sometimes freeing one * resource causes others to be freed (for example, when a window is * destroyed, so are its children). To do a complete job, Xlib would * have to maintain a large amount of state that currently resides only * in the server (the entire window tree in the above example). Even if * a less comprehensive strategy was adopted, such as recycling only * those IDs that Xlib can identify without maintaining additional * state, the additional bookkeeping at resource creation and * destruction time would likely introduce unacceptable overhead. * * To avoid the problems listed above, the server's complete knowledge * of all resource IDs in use by a client is leveraged. This extension * provides two ways for Xlib to query the server for available * resource IDs. Xlib can use these extension requests behind the * scenes when it has exhausted its current pool of resource IDs. */ /* If XC-MISC is present, we use it. Otherwise, we fall back to * allocate X resource ID sequentially to the end without recycling ID * (just as xlib does). * * Sample values: * resource base: 0x04000000 or 00000100000000000000000000000000b * resource mask: 0x003FFFFF or 00000000001111111111111111111111b */ if (!use_xcmisc) { // check if basic allocation fails use_xcmisc = (resource_index + 1 & ~resource_mask) != 0; } if (!use_xcmisc) { int id = resource_index++ | resource_base; resources.Add(id, obj); return(id); } if (xcmisc == null) { try { xcmisc = new XCMisc(this); } catch (NotFoundException e) { throw new Exception("Failed to allocate new resource id"); } } if (xcmisc_resource_count == 0) { // first time, or used up gnu.x11.extension.XCMisc.XIDRangeReply rr = xcmisc.xid_range(); xcmisc_resource_base = rr.start_id(); xcmisc_resource_count = rr.count(); } // give out in descending order xcmisc_resource_count--; return(xcmisc_resource_base + xcmisc_resource_count); }