Previous | Contents | Index |
This section includes an example that uses the following routines:
SET WM NORMAL HINTS
SET WM HINTS
SET WM WINDOW NAME
SET WM ICON NAME
SET CLASS HINT
Example 12-2 uses the following resource file to return values for such variables as window and icon position, name and size, font name, and colors. Using a resource data file is one method that the client can use to set properties. For more information about using the X resource manager, see Chapter 10.
star.window.name: Complying with ICCCM Conventions Example star.icon.name: Star star.font: -Adobe-New Century Schoolbook-Bold-R-NormaL--*-140-*-*-P-ISO8859-1 star.background: blue star.foreground: yellow star.border.color: black star.border.width: 2 star.window.height: 400 star.window.width: 600 star.window.x: 60 star.window.y: 70 star.window.maxHeight: 375 star.window.maxWidth: 475 star.window.minHeight: 120 star.window.minWidth: 350 star.icon.x: 800 star.icon.y: 10 |
Example 12-2 maps one window. When the user clicks MB1 on the minimize button, the window manager uses a bitmap to create a star as the icon pixmap. Clicking on MB2 exits the program. See Chapter 7 for more information about pixmaps and bitmaps.
Example 12-2 Setting Window Manager Properties |
---|
#include <decw$include/Xlib.h> #include <decw$include/Xutil.h> #include <decw$include/Xresource.h> #include <decw$include/Xatom.h> (1)#include "icon_file.dat" Display *dpy; Window win; GC gc; Screen *screen; int scrNum; Pixmap icon_win_pixmap; int n; int winX, winY, winHeight, winWidth; unsigned depth; unsigned long bd, fg, bg; unsigned long bw = 1; char *name, *class; char *fontname; char *message[]={ "This example demonstrates how applications", "can comply with ICCCM conventions." }; XrmDatabase star_db = 0; XrmValue value; XrmString type; XWMHints *xwmh; XSizeHints *xsh; XClassHint *xch; XSetWindowAttributes xswa; XGCValues xgcv; XTextProperty windowName, iconName; . . . /***** Create the Window using XSizeHints *****/ static void doCreateWindows( ) { (2) xsh = XAllocSizeHints(); xsh->flags = PMinSize | PMaxSize; xsh->min_height = atoi (doGetResource("star.window.minHeight", "Star.Window.MinHeight")); xsh->min_width = atoi (doGetResource("star.window.minWidth", "Star.Window.MinWidth")); xsh->max_height = atoi (doGetResource("star.window.maxHeight", "Star.Window.MaxHeight")); xsh->max_width = atoi (doGetResource("star.window.maxWidth", "Star.Window.MaxWidth")); xswa.event_mask = ExposureMask | ButtonPressMask; xswa.background_pixel = doDefineColor(doGetResource("star.background", "Star.Background")); winX = atoi (doGetResource("star.window.x", "Star.Window.X")); winY = atoi (doGetResource("star.window.y", "Star.Window.Y")); winWidth = atoi (doGetResource("star.window.width", "Star.Window.Width")); winHeight = atoi (doGetResource("star.window.height", "Star.Window.height")); win = XCreateWindow(dpy, DefaultRootWindow(dpy), winX, winY, winWidth, winHeight, 0, DefaultDepthOfScreen(screen), InputOutput, DefaultVisualOfScreen(screen), CWEventMask | CWBackPixel, &xswa); (3) XSetWMNormalHints(dpy, win, xsh); } /***** Set the window name and icon name *****/ static void doSetNames( ) { (4) windowName.value = (doGetResource("star.window.name", "Star.Window.Name")); windowName.encoding = XA_STRING; windowName.format = 8; windowName.nitems = strlen(windowName.value); (5) XSetWMName(dpy, win, &windowName); iconName.value = (doGetResource("star.icon.name", "Star.Icon.Name")); iconName.encoding = XA_STRING; iconName.format = 8; iconName.nitems = strlen(iconName.value); XSetWMIconName(dpy, win, &iconName); } /***** Create the graphics context *****/ static void doCreateGraphicsContext( ) { xgcv.foreground = doDefineColor(doGetResource("star.foreground", "Star.Foreground")); xgcv.background = doDefineColor(doGetResource("star.background", "Star.Background")); gc = XCreateGC(dpy, win, (GCForeground | GCBackground), &xgcv); } /**** Use the WM Hints data structure *****/ static void doWMHints ( ) { (6) xwmh = XAllocWMHints( ); xwmh->flags = (InputHint | StateHint | IconPixmapHint | IconWindowHint | IconPositionHint); xwmh->input = False; xwmh->initial_state = NormalState; /* Create the bitmap for the icon pixmap */ (7) if (xwmh->icon_pixmap = XCreateBitmapFromData(dpy, win, icon_file_bits, icon_file_width, icon_file_height)){ depth=DefaultDepth(dpy, DefaultScreen(dpy)); icon_win_pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), icon_file_width, icon_file_height, depth); XCopyPlane(dpy, xwmh->icon_pixmap, icon_win_pixmap, gc, 0, 0, icon_file_width, icon_file_height, 0, 0, 1); /* Create the icon window */ (8) xswa.background_pixmap = icon_win_pixmap; xswa.border_pixel = bd; xwmh->icon_window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, icon_file_width, icon_file_height, bw, CopyFromParent, InputOutput, CopyFromParent, (CWBackPixmap | CWBorderPixel), &xswa); XFreePixmap (dpy, icon_win_pixmap); xwmh->icon_x = atoi (doGetResource("star.icon.x", "Star.Icon.X")); xwmh->icon_y = atoi (doGetResource("star.icon.y", "Star.Icon.Y")); (9) XSetWMHints(dpy, win, xwmh); } else printf("Can't open bitmap file for icon\n"); /* Set the class hint data structure */ xch = XAllocClassHint( ); xch->res_name = "star"; xch->res_class = "Star"; (10) SetClassHint(dpy, win, xch); } /***** Load the font for text writing *****/ static void doLoadFont( ) { Font font; fontname = (doGetResource ("star.font", "Star.Font")); font = XLoadFont(dpy, fontname); XSetFont(dpy, gc, font); } /***** Map the window *****/ static void doMapWindow( ) { XMapWindow(dpy, win); } . . . /***** Button press & shutdown *****/ static void doButtonPress(eventP) XEvent *eventP; { if (eventP->xbutton.button == Button2) { XWithdrawWindow(dpy, win, scrNum); XFree(xwmh); XFree(xch); XFree(xsh); XCloseDisplay(dpy); exit(1); } } |
XSetWMNormalHints(display, window, hints) |
XSetWMName(display, window, text_property) |
The client also sets the icon name in the same manner with the SET
WM ICON NAME routine.
Xlib also provides a convenience function to set the standard window manager properties. Use the SET WM PROPERTIES routine to set the following window manager properties:
WM_CLASS
WM_CLIENT_MACHINE
WM_COMMAND
WM_HINTS
WM_ICON_NAME
WM_NAME
WM_NORMAL_HINTS
Example 12-3 illustrates how to use the SET WM PROPERTIES routine. This example is identical to Example 12-2 except that all properties are set at the end of the client-defined doWMHints routine.
Example 12-3 Using the SET WM PROPERTIES Routine |
---|
#include <decw$include/Xlib.h> #include <decw$include/Xutil.h> #include <decw$include/Xresource.h> #include <decw$include/Xatom.h> #include "icon_file.dat" Display *dpy; Window win; GC gc; Screen *screen; int scrNum; Pixmap icon_win_pixmap; int n; int winX, winY, winHeight, winWidth; unsigned depth; unsigned long bd, fg, bg; unsigned long bw = 1; char *name, *class; char *fontname; char *message[]={ "This example demonstrates how applications", "can set properties with one routine call." }; "This example demonstrates how applications", "can set properties with one routine call." }; XrmDatabase star_db = 0; XrmValue value; XrmString type; XWMHints *xwmh; XSizeHints *xsh; XClassHint *xch; XSetWindowAttributes xswa; XGCValues xgcv; XTextProperty windowName, iconName; . . . /***** Create the Window using XSizeHints *****/ static void doCreateWindows( ) { xsh = XAllocSizeHints(); xsh->flags = PMinSize | PMaxSize; xsh->min_height = atoi (doGetResource("star.window.minHeight", "Star.Window.MinHeight")); xsh->min_width = atoi (doGetResource("star.window.minWidth", "Star.Window.MinWidth")); xsh->max_height = atoi (doGetResource("star.window.maxHeight", "Star.Window.MaxHeight")); xsh->max_width = atoi (doGetResource("star.window.maxWidth", "Star.Window.MaxWidth")); xswa.event_mask = ExposureMask | ButtonPressMask; xswa.background_pixel = doDefineColor(doGetResource("star.background", "Star.Background")); winX = atoi (doGetResource("star.window.x", "Star.Window.X")); winY = atoi (doGetResource("star.window.y", "Star.Window.Y")); winWidth = atoi (doGetResource("star.window.width", "Star.Window.Width")); winHeight = atoi (doGetResource("star.window.height", "Star.Window.height")); win = XCreateWindow(dpy, DefaultRootWindow(dpy), winX, winY, winWidth, winHeight, DefaultDepthOfScreen(screen), InputOutput, DefaultVisualOfScreen(screen), CWEventMask | CWBackPixel, &xswa); } /***** Set the window name and icon name *****/ static void doSetNames( ) { windowName.value = (doGetResource("star.window.name", "Star.Window.Name")); windowName.encoding = XA_STRING; windowName.format = 8; windowName.nitems = strlen(windowName.value); iconName.value = (doGetResource("star.icon.name", "Star.Icon.Name")); iconName.encoding = XA_STRING; iconName.format = 8; iconName.nitems = strlen(iconName.value); } /***** Create the graphics context *****/ static void doCreateGraphicsContext( ) { xgcv.foreground = doDefineColor(doGetResource("star.foreground", "Star.Foreground")); xgcv.background = doDefineColor(doGetResource("star.background", "Star.Background")); gc = XCreateGC(dpy, win, (GCForeground | GCBackground), &xgcv); } /***** Use the WM Hints data structure *****/ static void doWMHints ( ) { xwmh = XAllocWMHints( ); xwmh->flags = (InputHint | StateHint | IconPixmapHint | IconWindowHint | IconPositionHint); xwmh->input = False; xwmh->initial_state = NormalState; /* Create the bitmap for the icon pixmap */ if (xwmh->icon_pixmap = XCreateBitmapFromData(dpy, win, icon_file_bits, icon_file_width, icon_file_height)){ depth=DefaultDepth(dpy, DefaultScreen(dpy)); icon_win_pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), icon_file_width, icon_file_height, depth); XCopyPlane(dpy, xwmh->icon_pixmap, icon_win_pixmap, gc, 0, 0, icon_file_width, icon_file_height, 0, 0, 1); /* Create the icon window */ xswa.background_pixmap = icon_win_pixmap; xswa.border_pixel = bd; xwmh->icon_window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, icon_file_width, icon_file_height, bw, CopyFromParent, InputOutput, CopyFromParent, (CWBackPixmap | CWBorderPixel), &xswa); XFreePixmap (dpy, icon_win_pixmap); xwmh->icon_x = atoi (doGetResource("star.icon.x", "Star.Icon.X")); xwmh->icon_y = atoi (doGetResource("star.icon.y", "Star.Icon.Y")); }else printf("Can't open bitmap file for icon\n"); /* Set the class hint data structure */ xch = XAllocClassHint( ); xch->res_name = "star"; xch->res_class = "Star"; (1)SetWMProperties(dpy, win, &windowName, &iconName, NULL, NULL, xsh, xwmh, xch); } /***** Load the font for text writing *****/ static void doLoadFont( ) { Font font; fontname = (doGetResource ("star.font", "Star.Font")); font = XLoadFont(dpy, fontname); XSetFont(dpy, gc, font); } /***** Map the window *****/ static void doMapWindow( ) { XMapWindow(dpy, win); } . . . /***** Button press & shutdown *****/ static void doButtonPress(eventP) XEvent *eventP; { if (eventP->xbutton.button == Button2) { XWithdrawWindow(dpy, win, scrNum); XFree(xwmh); XFree(xch); XFree(xsh); XCloseDisplay(dpy); exit(1); } } |
XSetWMProperties(display, window, window_name, icon_name, argv, argc, normal_hints, wm_hints, class_hints) |
VMS DECwindows includes a font compiler that enables programmers to convert an ASCII Bitmap Distribution Format (BDF) font into a binary server natural font (SNF). For information about the Bitmap Distribution Format, see the X Window System. The server uses an SNF file to display a font. In addition to converting the BDF file to binary form, the compiler provides statistical information about the font and the compilation process.
To invoke the font compiler, use the following DCL format:
FONT filename [ /[NO]OUTPUT[=output_file] /[NO]MINBBOX /[NO]REPORT[=report_file] ] |
The filename parameter specifies the BDF file to be compiled. A file name is required. The default file type is DECW$BDF.
The optional /OUTPUT qualifier specifies the file name of the resulting SNF file. The default output file name is the file name of the BDF file being compiled. The default output SNF file type is DECW$FONT. The default is /OUTPUT.
Compiler output consists of an SNF file that contains font information, character metrics, and the image of each character in the font. Font information in the SNF file is essentially the same as information stored in the font struct data structure. For a description of the data structure, see Section 8.1.
The optional /MINBBOX qualifier specifies that the compiler produce the minimum bounding box for each character in the font and adjust values for the left bearing, right bearing, ascent, and descent of each character accordingly. Character width is not affected. Specifying the /MINBBOX qualifier is equivalent to converting a fixed font to a monospaced font. For a description of character metrics and fonts, see Section 8.1. The default is /NOMINBBOX.
Using the /MINBBOX qualifier has two advantages. Because the font compiler produces minimum instead of fixed bounding boxes, the resulting SNF file is significantly smaller than the comparable fixed font SNF file. Consequently, both disk requirements for storing the font and server memory requirements when a client loads the font are reduced. In addition, because the resulting font comprises minimum inkable characters, server performance when writing text is increased.
The optional /REPORT qualifier directs the compiler to report information about the font and the compilation process, including BDF information, font properties, compiler generation information, and metrics. The /REPORT qualifier also causes the compiler to illustrate each glyph in the font. The default report file name is the file name of the BDF file being compiled. The default report file type is DECW$REP. The default is /NOREPORT.
Previous | Next | Contents | Index |