int main(int argc, char *argv[]) { char *dir = "tests"; unsigned int failed_checks; char c; TestContext *tc; List *tests; static const struct option long_options[] = { { "diff", required_argument, NULL, 'd' }, { "memory", no_argument, NULL, 'm' }, { "verbose", no_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; tc = test_context_new (); while (1) { int option_index = 0; c = getopt_long(argc, argv, OPTSTRING, long_options, &option_index); if (c == -1) break; switch (c) { case 'h': help(); return 0; case 'm': test_context_set_use_valgrind(tc); break; case 'v': test_context_set_verbosity(tc, MODE_VERBOSE); break; case 'q': test_context_set_verbosity(tc, MODE_QUIET); break; case 'V': printf("%s %s\n", PACKAGE_NAME, VERSION); return 0; case 'd': test_context_set_diff_opts(tc, optarg); break; default: usage(argv[0]); return 255; } } if (optind >= argc) { fprintf(stderr, "Missing command name\n"); return 253; } if (!test_context_set_command(tc, argv[optind])) { exit(EXIT_FAILURE); } if (++optind < argc) { dir = argv[optind]; } tests = test_load_from_dir(dir); if (tests == NULL) { fprintf(stderr, "No tests loaded from directory '%s'", dir); if (errno == 0) { fprintf(stderr, "\n"); } else { perror(""); } return 254; } failed_checks = test_context_run_tests(tc, tests); list_destroy(tests, DESTROYFUNC(test_free)); test_context_free(tc); return failed_checks; }
int main(int argc, char *argv[]) { Window window; int input_mask; XEvent event; testContext *cxt = test_context_new(); window = create_window(cxt); input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask; XSelectInput(cxt->display, window, input_mask); //设置要响应的事件 XMapWindow(cxt->display, window); XFlush(cxt->display); int x=0, y=0; int width=200, height=300; KeySym keysym; int num = 0; while (1) { XNextEvent(cxt->display, &event); //获取事件 if (event.type!=MotionNotify) fprintf(stdout, "event type:%d;%s\n", event.type, X11_EVENT_STRINGS[event.type]); switch (event.type) { case ButtonPress: #if 0 /*点一次按键就移动窗口并修改其尺寸*/ x+=30; y+=20; width += 40; height += 60; XMoveResizeWindow(cxt->display, window, x, y, width, height); #else /* 在窗口区域内按住鼠标左键进行拖动 */ XUngrabPointer(cxt->display, CurrentTime); //必须要有这句,没有这句不会产生拖动的效果。 Window child_window; XTranslateCoordinates(cxt->display, window, RootWindowOfScreen(cxt->screen), event.xbutton.x, event.xbutton.y, &x, &y, &child_window); /**< 加上这句解决鼠标拖动窗体时鼠标位置不对的问题 */ fprintf(stdout, "x:%d;y:%d;%d;%d\n", x, y, event.xbutton.x, event.xbutton.y); sendClientEvent(cxt, window, cxt->_NET_WM_MOVERESIZE, 5, x, y, 8, 1, 1); #endif break; case KeyPress: keysym = XLookupKeysym (&event.xkey, 0); if (XK_h == keysym) { fprintf(stdout, "h key press;try to hide\n"); XWithdrawWindow(cxt->display, window, cxt->screen_number); } else if (XK_m == keysym) { /* 窗口移动 */ XMoveWindow(cxt->display, window, 200, 100); } else if (XK_i == keysym) { /* 最小化 */ XIconifyWindow(cxt->display, window, cxt->screen_number); } else if (XK_a == keysym) { // 最大化 //_NET_WM_STATE_MAXIMIZED_{VERT,HORZ} indicates that the window is {vertically,horizontally} maximized sendClientEvent(cxt, window, cxt->_NET_WM_STATE, 4, 1, XInternAtom(cxt->display, "_NET_WM_STATE_MAXIMIZED_VERT", False), XInternAtom(cxt->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False), 0); } else if (XK_c == keysym) { fprintf(stdout, "c press\n"); // Cursor c = XcursorLibraryLoadCursor(cxt->display, "sb_v_double_arrow"); Cursor c = XcursorLibraryLoadCursor(cxt->display, "pencil"); XDefineCursor(cxt->display, window, c); } else if (XK_q == keysym) { fprintf(stdout, "try to quit\n"); exit(0); } break; case ConfigureNotify: if (num++>100) { int x, y; int child_x; int child_y; unsigned int mask; Window root_window; Window child_window; XQueryPointer(cxt->display, window, &root_window, &child_window, &x, &y, &child_x, &child_y, &mask); // 鼠标当前位置 fprintf(stdout, "button position-----------------%d %d %d %d \n", x, y, child_x, child_y); fprintf(stdout, "test to stop move=================\n"); // 停止窗口拖动 sendClientEvent(cxt, window, cxt->_NET_WM_MOVERESIZE, 5, 0, 0, 11, 1, 1); num = 0; } break; } } XDestroyWindow(cxt->display, window); XCloseDisplay(cxt->display); free(cxt); return 0; }