On Sun, Jan 25, 2004 at 03:36:33PM -0500, David Dawes wrote:
>On Sun, Jan 25, 2004 at 02:37:00PM -0500, David Dawes wrote:
>>On Sun, Jan 25, 2004 at 07:56:11PM +0100, Samuel Thibault wrote:
>>>Le dim 25 jan 2004 18:31:17 GMT, Andrew C Aitchison a tapoté sur son clavier :
>>>> First working hack at
>>>>    http://homepage.ntlworld.com/a.c.aitchison/VTprop.patch
>>>
>>>I would rather name the property CONTROL_VT (why the "XFree86" prefix ?)
>>>
>>>It will be resetted at regeneration, won't it ?
>>>I would hence have this code go in the
>>>for (i = 0; i < xf86NumScreens; i++)
>>>loop later, or even in xf86CreateRootWindow() (which, btw, erases
>>>properties, I'm wondering how this doesn't affect your hack)
>>>
>>
>>Yes, it does get reset at regeneration, because xf86CreateRootWindow()
>>frees the properties.  The only other plaace this is currently used is
>>xf86SetDDCproperties(), and it is typically not called at server
>>regeneration either.  Perhaps xf86CreateRootWindow() needs to
>>be modified to not clear the property list?
>
>It turns out that it is more complicated than just not freeing them.
>I think that xf86RegisterRootWindowProperty() needs to be modified to
>store the information in a static form so that the properties can be
>re-created by xf86CreateRootWindow() for each generation.

The patch below handles this, and includes Andrew's patch implmenting
the VT property.  It should handle properties registered only in the
first generation and those registered each generation.

If nobody reports any problems with it, I'll commit it.

David
-- 
David Dawes
developer/release engineer                      The XFree86 Project
www.XFree86.org/~dawes
Index: xf86.h
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86.h,v
retrieving revision 3.172
diff -u -r3.172 xf86.h
--- xf86.h      24 Sep 2003 02:43:16 -0000      3.172
+++ xf86.h      25 Jan 2004 20:56:19 -0000
@@ -57,7 +57,6 @@
 extern Bool xf86ResAccessEnter;
 extern ScrnInfoPtr *xf86Screens;       /* List of pointers to ScrnInfoRecs */
 extern const unsigned char byte_reversed[256];
-extern PropertyPtr *xf86RegisteredPropertiesTable;
 extern ScrnInfoPtr xf86CurrentScreen;
 extern Bool pciSlotClaimed;
 extern Bool isaSlotClaimed;
Index: xf86Globals.c
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c,v
retrieving revision 1.41
diff -u -r1.41 xf86Globals.c
--- xf86Globals.c       24 Aug 2003 17:36:52 -0000      1.41
+++ xf86Globals.c       25 Jan 2004 20:47:57 -0000
@@ -236,7 +236,7 @@
 Bool xf86MiscModInDevDisabled = FALSE;
 Bool xf86MiscModInDevAllowNonLocal = FALSE;
 #endif
-PropertyPtr *xf86RegisteredPropertiesTable = NULL;
+RootWinPropPtr *xf86RegisteredPropertiesTable = NULL;
 Bool xf86inSuspend = FALSE;
 
 #ifdef DLOPEN_HACK
Index: xf86Helper.c
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86Helper.c,v
retrieving revision 1.135
diff -u -r1.135 xf86Helper.c
--- xf86Helper.c        8 Oct 2003 14:58:27 -0000       1.135
+++ xf86Helper.c        25 Jan 2004 21:40:08 -0000
@@ -2888,11 +2888,12 @@
 xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
                               int format, unsigned long len, pointer value )
 {
-    PropertyPtr pNewProp, pRegProp;
+    RootWinPropPtr pNewProp = NULL, pRegProp;
     int i;
+    Bool existing = FALSE;
 
 #ifdef DEBUG
-    ErrorF("xf86RegisterRootWindowProperty(%d, %d, %d, %d, %d, %p)\n",
+    ErrorF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
           ScrnIndex, property, type, format, len, value);
 #endif
 
@@ -2900,19 +2901,35 @@
       return(BadMatch);
     }
 
-    if ( (pNewProp = (PropertyPtr)xalloc(sizeof(PropertyRec)))==NULL ) {
-      return(BadAlloc);
+    if (xf86RegisteredPropertiesTable &&
+       xf86RegisteredPropertiesTable[ScrnIndex]) {
+      for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex];
+          pNewProp; pNewProp = pNewProp->next) {
+       if (strcmp(pNewProp->name, NameForAtom(property)) == 0)
+         break;
+      }
     }
 
-    pNewProp->propertyName = property;
+    if (!pNewProp) {
+      if ((pNewProp = (RootWinPropPtr)xalloc(sizeof(RootWinProp))) == NULL) {
+       return(BadAlloc);
+      }
+      /*
+       * We will put this property at the end of the list so that
+       * the changes are made in the order they were requested.
+       */
+      pNewProp->next = NULL;
+    } else {
+      if (pNewProp->name)
+       xfree(pNewProp->name);
+      existing = TRUE;
+    }
+
+    pNewProp->name = xnfstrdup(NameForAtom(property));
     pNewProp->type = type;
     pNewProp->format = format;
     pNewProp->size = len;
     pNewProp->data = value;
-    /* We will put this property at the end of the list so that
-     * the changes are made in the order they were requested.
-     */
-    pNewProp->next = NULL;
  
 #ifdef DEBUG
     ErrorF("new property filled\n");
@@ -2923,7 +2940,7 @@
       ErrorF("creating xf86RegisteredPropertiesTable[] size %d\n",
             xf86NumScreens);
 #endif
-      if ( 
NULL==(xf86RegisteredPropertiesTable=(PropertyPtr*)xnfcalloc(sizeof(PropertyPtr),xf86NumScreens)
 )) {
+      if ( 
NULL==(xf86RegisteredPropertiesTable=(RootWinPropPtr*)xnfcalloc(sizeof(RootWinProp),xf86NumScreens)
 )) {
        return(BadAlloc);
       }
       for (i=0; i<xf86NumScreens; i++) {
@@ -2933,22 +2950,24 @@
 
 #ifdef DEBUG
     ErrorF("xf86RegisteredPropertiesTable %p\n",
-          xf86RegisteredPropertiesTable);
+          (void *)xf86RegisteredPropertiesTable);
     ErrorF("xf86RegisteredPropertiesTable[%d] %p\n",
-          ScrnIndex, xf86RegisteredPropertiesTable[ScrnIndex]);
+          ScrnIndex, (void *)xf86RegisteredPropertiesTable[ScrnIndex]);
 #endif
 
-    if ( xf86RegisteredPropertiesTable[ScrnIndex] == NULL) {
-      xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp;
-    } else {
-      pRegProp = xf86RegisteredPropertiesTable[ScrnIndex];
-      while (pRegProp->next != NULL) {
+    if (!existing) {
+      if ( xf86RegisteredPropertiesTable[ScrnIndex] == NULL) {
+       xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp;
+      } else {
+       pRegProp = xf86RegisteredPropertiesTable[ScrnIndex];
+       while (pRegProp->next != NULL) {
 #ifdef DEBUG
-       ErrorF("- next %p\n", pRegProp);
+         ErrorF("- next %p\n", (void *)pRegProp);
 #endif
-       pRegProp = pRegProp->next;
+         pRegProp = pRegProp->next;
+        }
+       pRegProp->next = pNewProp;
       }
-      pRegProp->next = pNewProp;
     }
 #ifdef DEBUG
     ErrorF("xf86RegisterRootWindowProperty succeeded\n");
Index: xf86Init.c
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v
retrieving revision 3.211
diff -u -r3.211 xf86Init.c
--- xf86Init.c  1 Nov 2003 00:47:01 -0000       3.211
+++ xf86Init.c  25 Jan 2004 21:46:51 -0000
@@ -155,7 +155,7 @@
   int ret = TRUE;
   int err = Success;
   ScreenPtr pScreen = pWin->drawable.pScreen;
-  PropertyPtr pRegProp, pOldRegProp;
+  RootWinPropPtr pProp;
   CreateWindowProcPtr CreateWindow =
     (CreateWindowProcPtr)(pScreen->devPrivates[xf86CreateRootWindowIndex].ptr);
 
@@ -181,25 +181,19 @@
   }
 
   /* Now do our stuff */
-
   if (xf86RegisteredPropertiesTable != NULL) {
     if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) {
-      for (pRegProp = xf86RegisteredPropertiesTable[pScreen->myNum];
-          pRegProp != NULL && err==Success;
-          pRegProp = pRegProp->next )
+      for (pProp = xf86RegisteredPropertiesTable[pScreen->myNum];
+          pProp != NULL && err==Success;
+          pProp = pProp->next )
        {
-         Atom oldNameAtom = pRegProp->propertyName;
-         char *nameString;
-         /* propertyName was created before the screen existed,
-          * so the atom does not belong to any screen;
-          * we need to create a new atom with the same name.
-          */
-         nameString = NameForAtom(oldNameAtom);
-         pRegProp->propertyName = MakeAtom(nameString, strlen(nameString), TRUE);
+         Atom prop;
+
+         prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE);
          err = ChangeWindowProperty(pWin,
-                                    pRegProp->propertyName, pRegProp->type,
-                                    pRegProp->format, PropModeReplace,
-                                    pRegProp->size, pRegProp->data,
+                                    prop, pProp->type,
+                                    pProp->format, PropModeReplace,
+                                    pProp->size, pProp->data,
                                     FALSE
                                     );
        }
@@ -207,14 +201,6 @@
       /* Look at err */
       ret &= (err==Success);
       
-      /* free memory */
-      pOldRegProp = xf86RegisteredPropertiesTable[pScreen->myNum];
-      while (pOldRegProp!=NULL) {      
-       pRegProp = pOldRegProp->next;
-       xfree(pOldRegProp);
-       pOldRegProp = pRegProp;
-      }  
-      xf86RegisteredPropertiesTable[pScreen->myNum] = NULL;
     } else {
       xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with "
              "non-root window %p (parent %p)\n",
@@ -303,7 +289,6 @@
       xf86ScreenIndex = AllocateScreenPrivateIndex();
       xf86CreateRootWindowIndex = AllocateScreenPrivateIndex();
       xf86PixmapIndex = AllocatePixmapPrivateIndex();
-      xf86RegisteredPropertiesTable=NULL;
       generation = serverGeneration;
   }
 
@@ -748,6 +733,32 @@
        }
     }
     formatsDone = TRUE;
+
+    if (xf86Info.vtno >= 0 ) {
+#define VT_ATOM_NAME         "XFree86_VT"
+      Atom VTAtom=-1;
+      CARD32  *VT = NULL;
+      int  ret;
+
+      /* This memory needs to stay available until the screen has been
+        initialized, and we can create the property for real.
+      */
+      if ( (VT = xalloc(sizeof(CARD32)))==NULL ) {
+       FatalError("Unable to make VT property - out of memory. Exiting...\n");
+      }
+      *VT = xf86Info.vtno;
+    
+      VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME), TRUE);
+
+      for (i = 0, ret = Success; i < xf86NumScreens && ret == Success; i++) {
+       ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
+                                            VTAtom, XA_INTEGER, 32, 
+                                            1, VT );
+       if (ret != Success)
+         xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
+                    "Failed to register VT property\n");
+      }
+    }
 
     /* If a screen uses depth 24, show what the pixmap format is */
     for (i = 0; i < xf86NumScreens; i++) {
Index: xf86Priv.h
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v
retrieving revision 3.82
diff -u -r3.82 xf86Priv.h
--- xf86Priv.h  9 Sep 2003 03:20:36 -0000       3.82
+++ xf86Priv.h  25 Jan 2004 20:56:50 -0000
@@ -113,6 +113,8 @@
 extern Bool xf86ProbeOnly;
 extern Bool xf86DoProbe;
 
+extern RootWinPropPtr *xf86RegisteredPropertiesTable;
+
 #ifndef DEFAULT_VERBOSE
 #define DEFAULT_VERBOSE                0
 #endif
Index: xf86Privstr.h
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h,v
retrieving revision 1.40
diff -u -r1.40 xf86Privstr.h
--- xf86Privstr.h       17 Oct 2003 20:02:12 -0000      1.40
+++ xf86Privstr.h       25 Jan 2004 21:17:30 -0000
@@ -198,6 +198,16 @@
 } VidModeRec, *VidModePtr;
 #endif
 
+/* Information for root window properties. */
+typedef struct _RootWinProp {
+    struct _RootWinProp *      next;
+    char *                     name;
+    Atom                       type;
+    short                      format;
+    long                       size;
+    pointer                    data;
+} RootWinProp, *RootWinPropPtr;
+
 /* private resource types */
 #define ResNoAvoid  ResBios
 

Reply via email to