static Window InitWindow(Display* dpy, int argc, char* argv[]) { static char* window_name = "Test Window Name"; static char* icon_name = "XTest"; XTextProperty windowName, iconName; int sn = DefaultScreen(dpy); unsigned dw = DisplayWidth(dpy, sn); unsigned dh = DisplayHeight(dpy, sn); XSizeHints size_hints = {0}; XWMHints wm_hints = {0}; XClassHint class_hints = {0}; Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, sn) , 0, 0, dw / 2, dh / 2, 0 // , BlackPixel(dpy, screen_num) // , WhitePixel(dpy, screen_num)); , 0x000000, 0x88FF88); //To avoid sending Expose message the a part of window is covered //set the mode to backup the covered part of the window if(DoesBackingStore(DefaultScreenOfDisplay(dpy)) == Always) { XSetWindowAttributes attr; //CWBackingStore - Backup covered window image (not repaint) //CWBitGravity - repaint on size change attr.backing_store = Always; //only for top-right // attr.bit_gravity = NorthWestGravity; //XChangeWindowAttributes keeps all other attr. unchanged XChangeWindowAttributes(dpy, win, CWBackingStore /*| CWBitGravity*/, &attr); } if(XStringListToTextProperty(&window_name, 1, &windowName) == 0) { perror("Structure allocation for windowName failed"); return 0; } if(XStringListToTextProperty(&icon_name, 1, &iconName) == 0) { perror("Structure allocation for iconName failed"); return 0; } size_hints.flags = PMinSize; size_hints.min_width = 200; size_hints.min_height = 100; wm_hints.flags = StateHint | InputHint; wm_hints.initial_state = NormalState; wm_hints.input = True; class_hints.res_name = argv[0]; class_hints.res_class = "xtest"; XSetWMProperties(dpy, win, &windowName, &iconName, argv, argc, &size_hints, &wm_hints, &class_hints); XFree(windowName.value); XFree(iconName.value); return win; }
/*###################### dir_expose_handler_line() ######################*/ void dir_expose_handler_line(Widget w, XtPointer client_data, XmDrawingAreaCallbackStruct *call_data) { static int ft_exposure_line = 0; /* first time exposure line. */ /* * To ensure that widgets are realized before calling XtAppAddTimeOut() * we wait for the widget to get its first expose event. This should * take care of the nasty BadDrawable error on slow connections. */ if (ft_exposure_line == 0) { int bs_attribute, i; Dimension height; Screen *c_screen = ScreenOfDisplay(display, DefaultScreen(display)); XFillRectangle(display, line_pixmap, default_bg_gc, 0, 0, window_width, (line_height * no_of_rows)); for (i = 0; i < no_of_dirs; i++) { draw_dir_line_status(i, 1); } (void)XtAppAddTimeOut(app, redraw_time_line, (XtTimerCallbackProc)check_dir_status, w); ft_exposure_line = 1; if ((bs_attribute = DoesBackingStore(c_screen)) != NotUseful) { XSetWindowAttributes attr; attr.backing_store = bs_attribute; attr.save_under = DoesSaveUnders(c_screen); XChangeWindowAttributes(display, line_window, CWBackingStore | CWSaveUnder, &attr); XChangeWindowAttributes(display, label_window, CWBackingStore, &attr); if (no_input == False) { XChangeWindowAttributes(display, XtWindow(mw[DIR_W]), CWBackingStore, &attr); if ((dcp.show_slog != NO_PERMISSION) || (dcp.show_rlog != NO_PERMISSION) || (dcp.show_tlog != NO_PERMISSION) || (dcp.show_ilog != NO_PERMISSION) || (dcp.show_olog != NO_PERMISSION) || (dcp.show_elog != NO_PERMISSION) || (dcp.info != NO_PERMISSION)) { XChangeWindowAttributes(display, XtWindow(mw[LOG_W]), CWBackingStore, &attr); } XChangeWindowAttributes(display, XtWindow(mw[CONFIG_W]), CWBackingStore, &attr); #ifdef _WITH_HELP_PULLDOWN XChangeWindowAttributes(display, XtWindow(mw[HELP_W]), CWBackingStore, &attr); #endif } /* if (no_input == False) */ } /* * Calculate the magic unkown height factor we need to add to the * height of the widget when it is being resized. */ XtVaGetValues(appshell, XmNheight, &height, NULL); magic_value = height - (window_height + line_height + glyph_height); } else { XEvent *p_event = call_data->event; XCopyArea(display, line_pixmap, line_window, color_letter_gc, p_event->xexpose.x, p_event->xexpose.y, p_event->xexpose.width, p_event->xexpose.height, p_event->xexpose.x, p_event->xexpose.y); } XFlush(display); return; }
int XDoesBackingStore(Screen *s) { return (DoesBackingStore(s)); }