Xnamespace: add per-client private data

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-01-25 16:38:10 +01:00
parent bc4c35d045
commit 33a66a7810
4 changed files with 61 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include "dix/dix_priv.h"
#include "include/extinit_priv.h" #include "include/extinit_priv.h"
#include "include/os.h" #include "include/os.h"
@ -10,6 +11,8 @@
Bool noNamespaceExtension = TRUE; Bool noNamespaceExtension = TRUE;
DevPrivateKeyRec namespaceClientPrivKeyRec = { 0 };
void void
NamespaceExtensionInit(void) NamespaceExtensionInit(void)
{ {
@ -20,4 +23,34 @@ NamespaceExtensionInit(void)
XNS_LOG("No config file. disabling Xns extension\n"); XNS_LOG("No config file. disabling Xns extension\n");
return; return;
} }
if (!dixRegisterPrivateKey
(&namespaceClientPrivKeyRec, PRIVATE_CLIENT, sizeof(struct XnamespaceClientPriv)))
FatalError("NamespaceExtensionInit: allocation failure\n");
/* Do the serverClient */
struct XnamespaceClientPriv *srv = XnsClientPriv(serverClient);
*srv = (struct XnamespaceClientPriv) { .isServer = TRUE };
XnamespaceAssignClient(srv, &ns_root);
}
void XnamespaceAssignClient(struct XnamespaceClientPriv *priv, struct Xnamespace *newns)
{
if (priv->ns != NULL)
priv->ns->refcnt--;
priv->ns = newns;
if (newns != NULL)
newns->refcnt++;
}
void XnamespaceAssignClientByName(struct XnamespaceClientPriv *priv, const char *name)
{
struct Xnamespace *newns = XnsFindByName(name);
if (newns == NULL)
newns = &ns_anon;
XnamespaceAssignClient(priv, newns);
} }

View File

@ -4,7 +4,9 @@
#include <stdio.h> #include <stdio.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include "include/dixstruct.h"
#include "include/list.h" #include "include/list.h"
#include "include/privates.h"
#include "include/window.h" #include "include/window.h"
struct Xnamespace { struct Xnamespace {
@ -19,11 +21,35 @@ extern struct xorg_list ns_list;
extern struct Xnamespace ns_root; extern struct Xnamespace ns_root;
extern struct Xnamespace ns_anon; extern struct Xnamespace ns_anon;
struct XnamespaceClientPriv {
Bool isServer;
XID authId;
struct Xnamespace* ns;
};
#define NS_NAME_ROOT "root" #define NS_NAME_ROOT "root"
#define NS_NAME_ANONYMOUS "anon" #define NS_NAME_ANONYMOUS "anon"
extern DevPrivateKeyRec namespaceClientPrivKeyRec;
Bool XnsLoadConfig(void); Bool XnsLoadConfig(void);
struct Xnamespace *XnsFindByName(const char* name); struct Xnamespace *XnsFindByName(const char* name);
void XnamespaceAssignClient(struct XnamespaceClientPriv *priv, struct Xnamespace *ns);
void XnamespaceAssignClientByName(struct XnamespaceClientPriv *priv, const char *name);
static inline struct XnamespaceClientPriv *XnsClientPriv(ClientPtr client) {
if (client == NULL) return NULL;
return dixLookupPrivate(&client->devPrivates, &namespaceClientPrivKeyRec);
}
static inline Bool XnsClientSameNS(struct XnamespaceClientPriv *p1, struct XnamespaceClientPriv *p2)
{
if (!p1 && !p2)
return TRUE;
if (!p1 || !p2)
return FALSE;
return (p1->ns == p2->ns);
}
#define XNS_LOG(...) do { printf("XNS "); printf(__VA_ARGS__); } while (0) #define XNS_LOG(...) do { printf("XNS "); printf(__VA_ARGS__); } while (0)

View File

@ -107,6 +107,7 @@ static const char *key_names[PRIVATE_LAST] = {
[PRIVATE_GLYPHSET] = "GLYPHSET", [PRIVATE_GLYPHSET] = "GLYPHSET",
[PRIVATE_PICTURE] = "PICTURE", [PRIVATE_PICTURE] = "PICTURE",
[PRIVATE_SYNC_FENCE] = "SYNC_FENCE", [PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
[PRIVATE_NAMESPACE] = "NAMESPACE",
}; };
static const Bool screen_specific_private[PRIVATE_LAST] = { static const Bool screen_specific_private[PRIVATE_LAST] = {

View File

@ -51,6 +51,7 @@ typedef enum {
PRIVATE_GLYPHSET, PRIVATE_GLYPHSET,
PRIVATE_PICTURE, PRIVATE_PICTURE,
PRIVATE_SYNC_FENCE, PRIVATE_SYNC_FENCE,
PRIVATE_NAMESPACE,
/* last private type */ /* last private type */
PRIVATE_LAST, PRIVATE_LAST,