dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/Xsharp RootWindow.cs,1.2,1.3 Xlib.cs


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/Xsharp RootWindow.cs,1.2,1.3 Xlib.cs.in,1.8,1.9 XsharpSupport.c,1.4,1.5
Date: Sat, 14 Jun 2003 05:50:54 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv12011/Xsharp

Modified Files:
        RootWindow.cs Xlib.cs.in XsharpSupport.c 
Log Message:


Adding some simple support for reading the RESOURCE_MANAGER property.


Index: RootWindow.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/RootWindow.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** RootWindow.cs       7 Jun 2003 00:13:09 -0000       1.2
--- RootWindow.cs       14 Jun 2003 09:50:51 -0000      1.3
***************
*** 22,27 ****
--- 22,29 ----
  {
  
+ using Xsharp.Events;
  using System;
  using System.Collections;
+ using System.Runtime.InteropServices;
  
  /// <summary>
***************
*** 34,37 ****
--- 36,43 ----
  public sealed class RootWindow : Widget
  {
+       // Internal state.
+       private Xlib.Atom resourceManager;
+       private String resources;
+ 
        // Constructor.  Called from the "Screen" class.
        internal RootWindow(Display dpy, Screen screen, Xlib.Window handle)
***************
*** 51,54 ****
--- 57,75 ----
                                mapped = true;
                                autoMapChildren = false;
+ 
+                               // Get the current state of the 
RESOURCE_MANAGER property.
+                               // We extract color theme information from it.
+                               resourceManager = Xlib.XInternAtom
+                                       (dpy.dpy, "RESOURCE_MANAGER", 
Xlib.Bool.False);
+                               IntPtr resptr = 
Xlib.XSharpGetResources(dpy.dpy, handle);
+                               if(resptr != IntPtr.Zero)
+                               {
+                                       resources = 
Marshal.PtrToStringAnsi(resptr);
+                                       Xlib.XSharpFreeResources(resptr);
+                               }
+ 
+                               // Select for property notifications so that we 
can
+                               // track changes to the RESOURCE_MANAGER 
property.
+                               SelectInput(EventMask.PropertyChangeMask);
                        }
  
***************
*** 160,163 ****
--- 181,287 ----
                                        throw new XInvalidOperationException
                                                (S._("X_NonRootOperation"));
+                               }
+                       }
+ 
+       /// <summary>
+       /// <para>Get the X resources on the root window.</para>
+       /// </summary>
+       ///
+       /// <value>
+       /// <para>The X resource string from the <c>RESOURCE_MANAGER</c>
+       /// property, or <see langword="null"/> if the property
+       /// is not currently set.</para>
+       /// </value>
+       ///
+       /// <remarks>
+       /// <para>The <c>ResourcesChanged</c> event will be emitted whenever
+       /// the X resource string changes.</para>
+       /// </remarks>
+       public String Resources
+                       {
+                               get
+                               {
+                                       return resources;
+                               }
+                       }
+ 
+       /// <summary>
+       /// <para>Event that is emitted when the X resources change.</para>
+       /// </summary>
+       public event EventHandler ResourcesChanged;
+ 
+       /// <summary>
+       /// <para>Get a named X resource value.</para>
+       /// </summary>
+       ///
+       /// <param name="name">
+       /// <para>The name of the resource value to retrieve.</para>
+       /// </param>
+       ///
+       /// <returns>
+       /// <para>The resource value, or <see langword="null"/> if there
+       /// is no resource called <paramref name="name"/>.</para>
+       /// </returns>
+       public String GetResource(String name)
+                       {
+                               if(resources == null)
+                               {
+                                       return null;
+                               }
+                               int posn = 0;
+                               int end;
+                               String value;
+                               while(posn != -1 && posn < resources.Length)
+                               {
+                                       if(resources[posn] == '\n')
+                                       {
+                                               ++posn;
+                                               continue;
+                                       }
+                                       if((posn + name.Length) >= 
resources.Length)
+                                       {
+                                               break;
+                                       }
+                                       if(String.CompareOrdinal(resources, 
posn, name, 0,
+                                                                               
         name.Length) == 0 &&
+                                          resources[posn + name.Length] == ':')
+                                       {
+                                               end = resources.IndexOf('\n', 
posn);
+                                               if(end == -1)
+                                               {
+                                                       end = resources.Length;
+                                               }
+                                               value = resources.Substring
+                                                       (posn + name.Length + 1,
+                                                        end - (posn + 
name.Length + 1));
+                                               return value.Trim();
+                                       }
+                                       posn = resources.IndexOf('\n', posn);
+                               }
+                               return null;
+                       }
+ 
+       /// Dispatch an event to this widget.
+       internal override void DispatchEvent(ref XEvent xevent)
+                       {
+                               if(xevent.type == EventType.PropertyNotify &&
+                                  xevent.xproperty.atom == resourceManager)
+                               {
+                                       // The "RESOURCE_MANAGER" property has 
changed.
+                                       IntPtr resptr = Xlib.XSharpGetResources
+                                                       (dpy.dpy, 
GetWidgetHandle());
+                                       if(resptr != IntPtr.Zero)
+                                       {
+                                               resources = 
Marshal.PtrToStringAnsi(resptr);
+                                               
Xlib.XSharpFreeResources(resptr);
+                                       }
+                                       else
+                                       {
+                                               resources = null;
+                                       }
+                                       if(ResourcesChanged != null)
+                                       {
+                                               ResourcesChanged(this, 
EventArgs.Empty);
+                                       }
                                }
                        }

Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** Xlib.cs.in  13 Jun 2003 02:39:29 -0000      1.8
--- Xlib.cs.in  14 Jun 2003 09:50:51 -0000      1.9
***************
*** 521,524 ****
--- 521,530 ----
                         out XRectangle max_logical_return);
  
+       [DllImport("XsharpSupport")]
+       extern public static IntPtr XSharpGetResources(IntPtr dpy, Window w);
+ 
+       [DllImport("XsharpSupport")]
+       extern public static void XSharpFreeResources(IntPtr value);
+ 
        // Helper functions from "libImlib.so" for loading images.
  

Index: XsharpSupport.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpSupport.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** XsharpSupport.c     9 Jun 2003 21:25:37 -0000       1.4
--- XsharpSupport.c     14 Jun 2003 09:50:51 -0000      1.5
***************
*** 22,25 ****
--- 22,26 ----
  
  #include <X11/Xlib.h>
+ #include <X11/Xatom.h>
  #ifdef WIN32
        #include <X11/Xwinsock.h>
***************
*** 287,290 ****
--- 288,340 ----
  }
  
+ /*
+  * Get the contents of the RESOURCE_MANAGER property on the root window.
+  */
+ char *XSharpGetResources(Display *dpy, Window root)
+ {
+       Atom resourceManager;
+       Atom actualTypeReturn;
+       int actualFormatReturn;
+       unsigned long nitemsReturn;
+       unsigned long bytesAfterReturn;
+       unsigned char *propReturn;
+ 
+       /* Register the RESOURCE_MANAGER atom with the X server */
+       resourceManager = XInternAtom(dpy, "RESOURCE_MANAGER", False);
+ 
+       /* Get the property, stopping at 1k characters */
+       propReturn = 0;
+       nitemsReturn = 0;
+       bytesAfterReturn = 0;
+       XGetWindowProperty(dpy, root, resourceManager, 0, 1024, False,
+                                          XA_STRING, &actualTypeReturn, 
&actualFormatReturn,
+                                          &nitemsReturn, &bytesAfterReturn, 
&propReturn);
+       if(bytesAfterReturn > 0)
+       {
+               /* We now know the real size, so fetch it properly this time */
+               if(propReturn)
+               {
+                       XFree((void *)propReturn);
+               }
+               propReturn = 0;
+               XGetWindowProperty(dpy, root, resourceManager, 0,
+                                                  (long)(1024 + 
bytesAfterReturn), False,
+                                                  XA_STRING, 
&actualTypeReturn, &actualFormatReturn,
+                                                  &nitemsReturn, 
&bytesAfterReturn, &propReturn);
+       }
+       return (char *)propReturn;
+ }
+ 
+ /*
+  * Free a return value from "XSharpGetResources".
+  */
+ void XSharpFreeResources(char *value)
+ {
+       if(value)
+       {
+               XFree((void *)value);
+       }
+ }
+ 
  #else /* X_DISPLAY_MISSING || !HAVE_SELECT */
  
***************
*** 318,321 ****
--- 368,382 ----
                                           void *max_ink_return,
                                           void *max_logical_return)
+ {
+       /* Nothing to do here */
+ }
+ 
+ char *XSharpGetResources(void *dpy, unsigned long root)
+ {
+       /* Nothing to do here */
+       return 0;
+ }
+ 
+ void XSharpFreeResources(char *value)
  {
        /* Nothing to do here */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]