Commit 427b7b97 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

nxagent: Use XlibAtom data type where appropriate

XlibAtom should be used wherever remote atoms are handled. This is important as Xlib data types and server data types of the same name do not always have identical sizes. See also https://lists.freedesktop.org/archives/xorg-devel/2015-August/047245.html
parent a261b724
...@@ -325,7 +325,7 @@ int nxagentQueryAtoms(ScreenPtr pScreen) ...@@ -325,7 +325,7 @@ int nxagentQueryAtoms(ScreenPtr pScreen)
typedef struct { typedef struct {
Atom local; Atom local;
Atom remote; XlibAtom remote;
const char *string; const char *string;
int length; int length;
} AtomMap; } AtomMap;
...@@ -335,8 +335,8 @@ static unsigned int privAtomMapSize = 0; ...@@ -335,8 +335,8 @@ static unsigned int privAtomMapSize = 0;
static unsigned int privLastAtom = 0; static unsigned int privLastAtom = 0;
static void nxagentExpandCache(void); static void nxagentExpandCache(void);
static void nxagentWriteAtom(Atom, Atom, const char*, Bool); static void nxagentWriteAtom(Atom, XlibAtom, const char*, Bool);
static AtomMap* nxagentFindAtomByRemoteValue(Atom); static AtomMap* nxagentFindAtomByRemoteValue(XlibAtom);
static AtomMap* nxagentFindAtomByLocalValue(Atom); static AtomMap* nxagentFindAtomByLocalValue(Atom);
static AtomMap* nxagentFindAtomByName(char*, unsigned); static AtomMap* nxagentFindAtomByName(char*, unsigned);
...@@ -357,7 +357,7 @@ static void nxagentExpandCache(void) ...@@ -357,7 +357,7 @@ static void nxagentExpandCache(void)
* consequent allocation, then cache the atom-couple. * consequent allocation, then cache the atom-couple.
*/ */
static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool duplicate) static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string, Bool duplicate)
{ {
const char *s; const char *s;
...@@ -532,7 +532,7 @@ static AtomMap* nxagentFindAtomByLocalValue(Atom local) ...@@ -532,7 +532,7 @@ static AtomMap* nxagentFindAtomByLocalValue(Atom local)
return NULL; return NULL;
} }
static AtomMap* nxagentFindAtomByRemoteValue(Atom remote) static AtomMap* nxagentFindAtomByRemoteValue(XlibAtom remote)
{ {
if (remote == None || remote == BAD_RESOURCE) if (remote == None || remote == BAD_RESOURCE)
{ {
...@@ -574,7 +574,7 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length) ...@@ -574,7 +574,7 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
* I think this and the 2 .*Find.* are the only functions to look for performances. * I think this and the 2 .*Find.* are the only functions to look for performances.
*/ */
Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
{ {
AtomMap *current; AtomMap *current;
...@@ -622,7 +622,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -622,7 +622,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
*/ */
{ {
Atom remote = XInternAtom(nxagentDisplay, string, !Makeit); XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit);
if (remote == None) if (remote == None)
{ {
...@@ -639,7 +639,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -639,7 +639,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
} }
} }
Atom nxagentLocalToRemoteAtom(Atom local) XlibAtom nxagentLocalToRemoteAtom(Atom local)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: entering\n", __func__); fprintf(stderr, "%s: entering\n", __func__);
...@@ -673,7 +673,7 @@ Atom nxagentLocalToRemoteAtom(Atom local) ...@@ -673,7 +673,7 @@ Atom nxagentLocalToRemoteAtom(Atom local)
const char *string = NameForAtom(local); const char *string = NameForAtom(local);
Atom remote = XInternAtom(nxagentDisplay, string, False); XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
if (remote == None) if (remote == None)
{ {
...@@ -693,7 +693,7 @@ Atom nxagentLocalToRemoteAtom(Atom local) ...@@ -693,7 +693,7 @@ Atom nxagentLocalToRemoteAtom(Atom local)
return remote; return remote;
} }
Atom nxagentRemoteToLocalAtom(Atom remote) Atom nxagentRemoteToLocalAtom(XlibAtom remote)
{ {
if (remote == None || remote == BAD_RESOURCE) if (remote == None || remote == BAD_RESOURCE)
{ {
......
...@@ -51,23 +51,33 @@ void nxagentInitAtoms(); ...@@ -51,23 +51,33 @@ void nxagentInitAtoms();
int nxagentQueryAtoms(ScreenPtr pScreen); int nxagentQueryAtoms(ScreenPtr pScreen);
void nxagentResetAtomMap(void);
void nxagentWMDetect(void);
#ifdef XlibAtom
/*
* only provide these protoypes if the including file knows about Xlib
* types. This allows us including Atoms.h without having to use the
* Xlib type magic of Agent.h
*/
/* /*
* Create the atoms on the remote X server * Create the atoms on the remote X server
* and cache the couple local-remote atoms. * and cache the couple local-remote atoms.
*/ */
Atom nxagentMakeAtom(char *, unsigned, Bool); XlibAtom nxagentMakeAtom(char *, unsigned, Bool);
/* /*
* Converts local atoms in remote atoms and * Converts local atoms in remote atoms and
* viceversa. * viceversa.
*/ */
Atom nxagentRemoteToLocalAtom(Atom); Atom nxagentRemoteToLocalAtom(XlibAtom);
Atom nxagentLocalToRemoteAtom(Atom); XlibAtom nxagentLocalToRemoteAtom(Atom);
void nxagentResetAtomMap(void); #endif
void nxagentWMDetect(void);
#endif /* __Atoms_H__ */ #endif /* __Atoms_H__ */
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include "windowstr.h" #include "windowstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "Agent.h"
#include "Windows.h" #include "Windows.h"
#include "Atoms.h" #include "Atoms.h"
#include "Agent.h"
#include "Args.h" #include "Args.h"
#include "Trap.h" #include "Trap.h"
#include "Rootless.h" #include "Rootless.h"
...@@ -72,7 +72,7 @@ static int agentClipboardStatus; ...@@ -72,7 +72,7 @@ static int agentClipboardStatus;
static int clientAccum; static int clientAccum;
#endif #endif
Atom serverCutProperty; XlibAtom serverCutProperty;
Atom clientCutProperty; Atom clientCutProperty;
static Window serverWindow; static Window serverWindow;
...@@ -82,7 +82,7 @@ const int nxagentMaxSelections = 2; ...@@ -82,7 +82,7 @@ const int nxagentMaxSelections = 2;
typedef struct _SelectionOwner typedef struct _SelectionOwner
{ {
Atom selection; /* _external_ Atom */ XlibAtom selection; /* _external_ Atom */
ClientPtr client; /* internal client */ ClientPtr client; /* internal client */
Window window; /* internal window id */ Window window; /* internal window id */
WindowPtr windowPtr; /* internal window struct */ WindowPtr windowPtr; /* internal window struct */
...@@ -96,7 +96,7 @@ typedef struct _SelectionOwner ...@@ -96,7 +96,7 @@ typedef struct _SelectionOwner
* external atom of the selection * external atom of the selection
*/ */
static SelectionOwner *lastSelectionOwner; static SelectionOwner *lastSelectionOwner;
static Atom nxagentLastRequestedSelection; static XlibAtom nxagentLastRequestedSelection;
/* /*
* Needed to handle the notify selection event to * Needed to handle the notify selection event to
...@@ -126,15 +126,15 @@ static unsigned long lastClientPropertySize; ...@@ -126,15 +126,15 @@ static unsigned long lastClientPropertySize;
static ClientSelectionStage lastClientStage; static ClientSelectionStage lastClientStage;
static Window lastServerRequestor; static Window lastServerRequestor;
static Atom lastServerProperty; static XlibAtom lastServerProperty;
static Atom lastServerTarget; static XlibAtom lastServerTarget;
static Time lastServerTime; static Time lastServerTime;
static Atom serverTARGETS; static XlibAtom serverTARGETS;
static Atom serverTIMESTAMP; static XlibAtom serverTIMESTAMP;
static Atom serverTEXT; static XlibAtom serverTEXT;
static Atom serverUTF8_STRING; static XlibAtom serverUTF8_STRING;
static Atom serverClientCutProperty; static XlibAtom serverClientCutProperty;
static Atom clientTARGETS; static Atom clientTARGETS;
static Atom clientTEXT; static Atom clientTEXT;
static Atom clientCOMPOUND_TEXT; static Atom clientCOMPOUND_TEXT;
...@@ -209,7 +209,7 @@ XFixesAgentInfoRec nxagentXFixesInfo = { -1, -1, -1, 0 }; ...@@ -209,7 +209,7 @@ XFixesAgentInfoRec nxagentXFixesInfo = { -1, -1, -1, 0 };
extern Display *nxagentDisplay; extern Display *nxagentDisplay;
Bool nxagentValidServerTargets(Atom target); Bool nxagentValidServerTargets(XlibAtom target);
static void endTransfer(Bool success); static void endTransfer(Bool success);
#define SELECTION_SUCCESS True #define SELECTION_SUCCESS True
#define SELECTION_FAULT False #define SELECTION_FAULT False
...@@ -448,7 +448,7 @@ int SendSelectionNotifyEventToClient(ClientPtr client, ...@@ -448,7 +448,7 @@ int SendSelectionNotifyEventToClient(ClientPtr client,
* server, like .e.g XA_STRING or UTF8_STRING. Other, non content type * server, like .e.g XA_STRING or UTF8_STRING. Other, non content type
* targets like "TARGETS" or "TIMESTAMP" will return false. * targets like "TARGETS" or "TIMESTAMP" will return false.
*/ */
Bool nxagentValidServerTargets(Atom target) Bool nxagentValidServerTargets(XlibAtom target)
{ {
if (target == XA_STRING) if (target == XA_STRING)
{ {
...@@ -553,7 +553,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -553,7 +553,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
nxagentPrintClipboardStat("after nxagentClearClipboard"); nxagentPrintClipboardStat("after nxagentClearClipboard");
} }
int nxagentFindLastSelectionOwnerIndex(Atom sel) int nxagentFindLastSelectionOwnerIndex(XlibAtom sel)
{ {
int i = 0; int i = 0;
while ((i < nxagentMaxSelections) && while ((i < nxagentMaxSelections) &&
...@@ -1992,7 +1992,6 @@ int nxagentSendNotify(xEvent *event) ...@@ -1992,7 +1992,6 @@ int nxagentSendNotify(xEvent *event)
WindowPtr nxagentGetClipboardWindow(Atom property) WindowPtr nxagentGetClipboardWindow(Atom property)
{ {
int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection); int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection);
if ((i < nxagentMaxSelections) && (property == clientCutProperty) && if ((i < nxagentMaxSelections) && (property == clientCutProperty) &&
(lastSelectionOwner[i].windowPtr != NULL)) (lastSelectionOwner[i].windowPtr != NULL))
{ {
......
...@@ -1355,25 +1355,21 @@ static void nxagentXkbGetNames(void) ...@@ -1355,25 +1355,21 @@ static void nxagentXkbGetNames(void)
if (nxagentRemoteRules) if (nxagentRemoteRules)
return; return;
Atom atom = XInternAtom(nxagentDisplay, "_XKB_RULES_NAMES", 1); XlibAtom rulesprop = XInternAtom(nxagentDisplay, "_XKB_RULES_NAMES", 1);
if (atom == 0) if (rulesprop == 0)
{ {
return; return;
} }
#ifdef _XSERVER64 XlibAtom type;
Atom64 type;
#else
Atom type;
#endif
int format; int format;
unsigned long n; unsigned long n;
unsigned long after; unsigned long after;
char *data = NULL; char *data = NULL;
Status result = XGetWindowProperty(nxagentDisplay, DefaultRootWindow(nxagentDisplay), Status result = XGetWindowProperty(nxagentDisplay, DefaultRootWindow(nxagentDisplay),
atom, 0, 256, 0, XA_STRING, &type, &format, rulesprop, 0, 256, 0, XA_STRING, &type, &format,
&n, &after, (unsigned char **)&data); &n, &after, (unsigned char **)&data);
if (result != Success || !data) if (result != Success || !data)
......
...@@ -706,8 +706,8 @@ int nxagentExportProperty(WindowPtr pWin, ...@@ -706,8 +706,8 @@ int nxagentExportProperty(WindowPtr pWin,
if (export) if (export)
{ {
Atom propertyX = nxagentLocalToRemoteAtom(property); XlibAtom propertyX = nxagentLocalToRemoteAtom(property);
Atom typeX = nxagentLocalToRemoteAtom(type); XlibAtom typeX = nxagentLocalToRemoteAtom(type);
if (propertyX == None || typeX == None) if (propertyX == None || typeX == None)
{ {
...@@ -794,8 +794,8 @@ int nxagentExportProperty(WindowPtr pWin, ...@@ -794,8 +794,8 @@ int nxagentExportProperty(WindowPtr pWin,
} }
void nxagentImportProperty(Window window, void nxagentImportProperty(Window window,
Atom property, XlibAtom property,
Atom type, XlibAtom type,
int format, int format,
unsigned long nitems, unsigned long nitems,
unsigned long bytes_after, unsigned long bytes_after,
...@@ -1001,7 +1001,7 @@ void nxagentImportProperty(Window window, ...@@ -1001,7 +1001,7 @@ void nxagentImportProperty(Window window,
else if (strcmp(typeS, "ATOM") == 0) else if (strcmp(typeS, "ATOM") == 0)
{ {
Atom *atoms = malloc(nitems * sizeof(Atom)); Atom *atoms = malloc(nitems * sizeof(Atom));
Atom *input = (Atom*) buffer; XlibAtom *input = (XlibAtom*) buffer;
if (atoms == NULL) if (atoms == NULL)
{ {
...@@ -1107,7 +1107,7 @@ void nxagentImportProperty(Window window, ...@@ -1107,7 +1107,7 @@ void nxagentImportProperty(Window window,
struct nxagentPropertyRec{ struct nxagentPropertyRec{
Window window; Window window;
Atom property; XlibAtom property;
struct nxagentPropertyRec *next; struct nxagentPropertyRec *next;
}; };
...@@ -1148,7 +1148,7 @@ void nxagentRemovePropertyFromList(void) ...@@ -1148,7 +1148,7 @@ void nxagentRemovePropertyFromList(void)
* Add the record to the list. * Add the record to the list.
*/ */
void nxagentAddPropertyToList(Atom property, WindowPtr pWin) void nxagentAddPropertyToList(XlibAtom property, WindowPtr pWin)
{ {
if (NXDisplayError(nxagentDisplay) == 1) if (NXDisplayError(nxagentDisplay) == 1)
{ {
......
...@@ -46,13 +46,15 @@ extern WindowPtr nxagentRootlessWindow; ...@@ -46,13 +46,15 @@ extern WindowPtr nxagentRootlessWindow;
* connected to the real X server. * connected to the real X server.
*/ */
#ifdef XlibAtom
typedef struct typedef struct
{ {
Window window; Window window;
Atom property; XlibAtom property;
} PropertyRequestRec; } PropertyRequestRec;
extern PropertyRequestRec nxagentPropertyRequests[256]; extern PropertyRequestRec nxagentPropertyRequests[256];
#endif
Window nxagentRootlessWindowParent(WindowPtr pWin); Window nxagentRootlessWindowParent(WindowPtr pWin);
...@@ -75,14 +77,18 @@ int nxagentExportProperty(WindowPtr pWin, Atom property, Atom type, int format, ...@@ -75,14 +77,18 @@ int nxagentExportProperty(WindowPtr pWin, Atom property, Atom type, int format,
#define MAX_RETRIEVED_PROPERTY_SIZE 256 * 1024 #define MAX_RETRIEVED_PROPERTY_SIZE 256 * 1024
void nxagentImportProperty(Window window, Atom property, Atom type, int format, #ifdef XlibAtom
void nxagentImportProperty(Window window, XlibAtom property, XlibAtom type, int format,
unsigned long nitems, unsigned long bytes_after, unsigned char *buffer); unsigned long nitems, unsigned long bytes_after, unsigned char *buffer);
#endif
/* /*
* Push last ChangeProperty to the list. * Push last ChangeProperty to the list.
*/ */
void nxagentAddPropertyToList(Atom property, WindowPtr pWin); #ifdef XlibAtom
void nxagentAddPropertyToList(XlibAtom property, WindowPtr pWin);
#endif
/* /*
* Check if a PropertyNotify match the top * Check if a PropertyNotify match the top
......
...@@ -149,7 +149,7 @@ Window nxagentInputWindows[MAXSCREENS]; ...@@ -149,7 +149,7 @@ Window nxagentInputWindows[MAXSCREENS];
Window nxagentScreenSaverWindows[MAXSCREENS]; Window nxagentScreenSaverWindows[MAXSCREENS];
#ifdef NXAGENT_ONSTART #ifdef NXAGENT_ONSTART
Atom nxagentReadyAtom; XlibAtom nxagentReadyAtom;
#endif #endif
ScreenPtr nxagentDefaultScreen = NULL; ScreenPtr nxagentDefaultScreen = NULL;
......
...@@ -49,6 +49,12 @@ is" without express or implied warranty. ...@@ -49,6 +49,12 @@ is" without express or implied warranty.
#define nxagentSetPrintGeometry(screen) \ #define nxagentSetPrintGeometry(screen) \
nxagentPrintGeometryFlags = (1 << (screen)); nxagentPrintGeometryFlags = (1 << (screen));
#ifdef NXAGENT_ONSTART
#ifdef XlibAtom
extern XlibAtom nxagentReadyAtom;
#endif
#endif
extern int nxagentClients; extern int nxagentClients;
extern int nxagentAutoDisconnectTimeout; extern int nxagentAutoDisconnectTimeout;
......
...@@ -69,20 +69,6 @@ Bool nxagentWMPassed = False; ...@@ -69,20 +69,6 @@ Bool nxagentWMPassed = False;
static void nxagentPaintLogo(Window win, GC gc, int scale, int width, int height); static void nxagentPaintLogo(Window win, GC gc, int scale, int width, int height);
/*
* From Screen.c.
*/
#ifdef NXAGENT_ONSTART
extern Atom nxagentReadyAtom;
#endif
/*
* From Clipboard.c.
*/
extern Atom serverCutProperty;
void nxagentShowSplashWindow(Window parentWindow) void nxagentShowSplashWindow(Window parentWindow)
{ {
XWindowAttributes getAttributes; XWindowAttributes getAttributes;
......
...@@ -422,7 +422,7 @@ Bool nxagentCreateWindow(WindowPtr pWin) ...@@ -422,7 +422,7 @@ Bool nxagentCreateWindow(WindowPtr pWin)
if (nxagentOption(Rootless) && nxagentWindowTopLevel(pWin)) if (nxagentOption(Rootless) && nxagentWindowTopLevel(pWin))
{ {
Atom prop = nxagentMakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), True); XlibAtom prop = nxagentMakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), True);
XlibAtom atom = nxagentMakeAtom("WM_DELETE_WINDOW", strlen("WM_DELETE_WINDOW"), True); XlibAtom atom = nxagentMakeAtom("WM_DELETE_WINDOW", strlen("WM_DELETE_WINDOW"), True);
XSetWMProtocols(nxagentDisplay, nxagentWindowPriv(pWin)->window, &atom, 1); XSetWMProtocols(nxagentDisplay, nxagentWindowPriv(pWin)->window, &atom, 1);
...@@ -3054,8 +3054,7 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer ...@@ -3054,8 +3054,7 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer
{ {
if (nxagentWindowTopLevel(pWin)) if (nxagentWindowTopLevel(pWin))
{ {
Atom prop = nxagentMakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), True); XlibAtom prop = nxagentMakeAtom("WM_PROTOCOLS", strlen("WM_PROTOCOLS"), True);
XlibAtom atom = nxagentMakeAtom("WM_DELETE_WINDOW", strlen("WM_DELETE_WINDOW"), True); XlibAtom atom = nxagentMakeAtom("WM_DELETE_WINDOW", strlen("WM_DELETE_WINDOW"), True);
XSetWMProtocols(nxagentDisplay, nxagentWindow(pWin), &atom, 1); XSetWMProtocols(nxagentDisplay, nxagentWindow(pWin), &atom, 1);
......
...@@ -177,7 +177,9 @@ do\ ...@@ -177,7 +177,9 @@ do\
WindowPtr nxagentWindowPtr(Window window); WindowPtr nxagentWindowPtr(Window window);
extern Atom serverCutProperty; #ifdef XlibAtom
extern XlibAtom serverCutProperty;
#endif
/* /*
* If the rectangles in an exposed region exceed * If the rectangles in an exposed region exceed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment