我正在用C编写我的第一个X11应用程序,并且在尝试检索我的应用程序窗口的大小时遇到了一个主要问题。“使指针不受整型影响” - 如何满足GCC?
temp.c:30:2 warning: passing argument 3 of 'XGetGeometry' makes pointer from integer without a cast
我知道这只是一个警告,但它仍然导致段错误这是不好玩。这里是我的代码:
static void loop();
static void initialize();
static void cleanUp();
static void run();
/* Variables */
static int screenNumber;
unsigned long White;
unsigned long Black;
long eventMask;
static Display *currentDisplay;
static Window currentWindow;
static unsigned int windowWidth;
static unsigned int windowHeight;
static GC graphicsController;
static XEvent XEvents;
void loop() {
XGetGeometry(currentDisplay, currentWindow, DefaultRootWindow(currentDisplay), NULL, NULL, &windowWidth, &windowHeight, NULL, NULL);
XDrawLine(currentDisplay, currentWindow, graphicsController, 0, 0, (int)windowWidth, (int)windowHeight);
XDrawLine(currentDisplay, currentWindow, graphicsController, 0, (int)windowHeight, (int)windowWidth, 0);
}
void initialize() {
currentDisplay = XOpenDisplay(NULL);
screenNumber = DefaultScreen(currentDisplay);
White = WhitePixel(currentDisplay, screenNumber);
Black = BlackPixel(currentDisplay, screenNumber);
currentWindow = XCreateSimpleWindow( currentDisplay,
DefaultRootWindow(currentDisplay),
0, 0,
500, 500,
0, Black,
White);
XMapWindow(currentDisplay, currentWindow);
XStoreName(currentDisplay, currentWindow, "rGot - X11");
eventMask = StructureNotifyMask;
XSelectInput(currentDisplay, currentWindow, eventMask);
do{
XNextEvent(currentDisplay, &XEvents);
}while(XEvents.type != MapNotify);
graphicsController = XCreateGC(currentDisplay, currentWindow, 0, NULL);
XSetForeground(currentDisplay, graphicsController, Black);
}
void run() {
eventMask = ButtonPressMask|ButtonReleaseMask;
XSelectInput(currentDisplay, currentWindow, eventMask);
do{
XNextEvent(currentDisplay, &XEvents);
loop();
}while(1==1);
}
void cleanUp() {
XDestroyWindow(currentDisplay, currentWindow);
XCloseDisplay(currentDisplay);
}
int main(){
initialize();
run();
cleanUp();
return 0;
}
我知道我在做什么毛病我的指针“东经这样的,但我是相当新的这...这里是我的设置:
- 的Ubuntu 12.04 LTS
- 与编译:
gcc tempc -o temp -lX11
对于那些后来发现这一点 - 我利用初步尝试210是完全错误的!
要正确地使用它,我必须做到以下几点:
XGetGeometry(currentDisplay, currentWindow, ¤tRoot, &windowOffsetX, &windowOffsetY, &windowWidth, &windowHeight, &windowBorderWidth, &windowDepth);
这是基于从我的调查结果here的。
您需要回答的问题是*为什么*您要调用'XGetGeometry'。如果没有弄清楚你想用它做什么,你就无法使电话正确。 –
@ n.m。,我的目标是获得我窗户的大小。我能够获得屏幕的大小,但我需要知道我的实际窗口的大小。 – FreeSnow
对不起,我误解了你的代码。以某种方式错过了'&windowWidth,&windowHeight'。所以这部分是正确的,我只是让自己看起来很愚蠢。唯一的问题是根窗口是返回参数。 –