Xlib中的如何将窗口在创建时指定或移动到屏幕范围之外呢?
我想让一个窗口在初始化时不可见,想通过改变窗口xy座标来实现,初始化好后再移回来,但是XMoveWindow方法似乎每次都要自动将窗口计算到桌面之内,请教各位如何让它不要这么聪明呢?
程序代码如下:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* Global variables */
Display * display;
int screen_num;
static char * appname;
/* main() function */
int main( int argc, char * argv[] ) {
/* Window variables */
Window win;
int x, y;
unsigned int width, height;
unsigned int border_width;
/* Display variables */
char * display_name = NULL;
unsigned int display_width, display_height;
/* Miscellaneous X variables */
XSizeHints * size_hints;
XWMHints * wm_hints;
XClassHint * class_hints;
XEvent report;
appname = argv[0];
/* Allocate memory for our structures */
if ( !( size_hints = XAllocSizeHints() ) ||
!( wm_hints = XAllocWMHints() ) ||
!( class_hints = XAllocClassHint() ) ) {
fprintf(stderr, "%s: couldn't allocate memory.\n", appname);
exit(EXIT_FAILURE);
}
/* Connect to X server */
if ( (display = XOpenDisplay(display_name)) == NULL ) {
fprintf(stderr, "%s: couldn't connect to X server %s\n",
appname, display_name);
exit(EXIT_FAILURE);
}
/* Get screen size from display structure macro */
screen_num = DefaultScreen(display);
display_width = DisplayWidth(display, screen_num);
display_height = DisplayHeight(display, screen_num);
/* Set initial window size and position, and create it */
x = 0;
y = 0;
width = 500;
height = 300;
win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
x, y, width, height, border_width,
BlackPixel(display, screen_num),
WhitePixel(display, screen_num));
/* Display Window */
XMapWindow(display, win);
XMoveWindow(display, win,1500,100);
/* Enter event loop */
XNextEvent(display, &report);
return EXIT_SUCCESS; /* We shouldn't get here */
}
编译 gcc -o test test.c -Wall -L/usr/X11R6/lib -lX11