1common(1) AfterStep X11 window manager common(1)
2
3
4
6 common - common functions used in other examples libAfterImage/tutoriā
7 als/common.h
8
10 Generic Xlib related functionality, common for all the tutorials.
11
13 libAfterImage,
14 ASView, ASScale, ASTile, ASMerge, ASGrad, ASFlip, ASText
15
18 _XA_WM_DELETE_WINDOW - stores value of X Atom "WM_DELETE_WINDOW".
19
21 In X all client's top level windows are managed by window manager.
22 That includes moving, resizing, decorating, focusing and closing of
23 windows. Interactions between window manager and client window are
24 governed by ICCCM specification.
25 All the parts of this specification are completely optional, but it
26 is recommended that the following minimum set of hints be supplied
27 for any client window:
28 Window's title(WM_NAME), iconified window title(WM_ICON_NAME), class
29 hint (WM_CLASS) and supported protocols (WM_PROTOCOLS). It is
30 recommended also that WM_DELETE_WINDOW protocol be supported, as
31 otherwise there are no way to safely close client window, but to
32 kill it.
33 All of the above mentioned hints are identified by atoms that have
34 standard preset values, except for WM_DELETE_WINDOW. As the result we
35 need to obtain WM_DELETE_WINDOW atoms ID explicitly. We use
36 _XA_WM_DELETE_WINDOW to store the ID of that atom, so it is accessible
37 anywhere from our application.
38
40 Source :
41 Atom _XA_WM_DELETE_WINDOW = None;
42
45 Window create_top_level_window( ASVisual *asv, Window root,
46 int x, int y,
47 unsigned int width,
48 unsigned int height,
49 unsigned int border_width,
50 unsigned long attr_mask,
51 XSetWindowAttributes *attr,
52 char *app_class );
53
55 asv - pointer to valid preinitialized ASVisual structure.
56
57 root - root window of the screen on which to create window.
58
59 x, y - desired position of the window
60
61 width, height - desired window size.
62
63 border_width
64 - desired initial border width of the window (may not have any
65 effect due to Window Manager intervention.
66
67 attr_mask
68 - mask of the attributes that has to be set on the window
69
70 attr - values of the attributes to be set.
71
72 app_class
73 - title of the application to be used as its window Title and
74 resources class.
75
76
78 ID of the created window.
79
81 create_top_level_window() is autyomating process of creating top
82 level application window. It creates window for specified ASVisual,
83 and then sets up basic ICCCM hints for that window, such as WM_NAME,
84 WM_ICON_NAME, WM_CLASS and WM_PROTOCOLS.
85
87 Source :
88 Window
89 create_top_level_window( ASVisual *asv, Window root, int x, int y,
90 unsigned int width, unsigned int height,
91 unsigned int border_width,
92 unsigned long attr_mask,
93 XSetWindowAttributes *attr,
94 const char *app_class, const char *app_name )
95 {
96 Window w = None;
97 #ifndef X_DISPLAY_MISSING
98 char *tmp ;
99 XTextProperty name;
100 XClassHint class1;
101
102 w = create_visual_window(asv, root, x, y, width, height, border_width,
103 InputOutput, attr_mask, attr );
104
105 tmp = (app_name==NULL)?(char*)get_application_name():(char*)app_name;
106 XStringListToTextProperty (&tmp, 1, &name);
107
108 class1.res_name = tmp; /* for future use */
109 class1.res_class = (char*)app_class;
110 XSetWMProtocols (dpy, w, &_XA_WM_DELETE_WINDOW, 1);
111 XSetWMProperties (dpy, w, &name, &name, NULL, 0, NULL, NULL, &class1);
112 /* final cleanup */
113 XFree ((char *) name.value);
114
115 #endif /* X_DISPLAY_MISSING */
116 return w;
117 }
118
121 Pixmap set_window_background_and_free( Window w, Pixmap p );
122
124 w - ID of the window background of which we need to set.
125
126 p - Pixmap to set background to.
127
128
130 None on success. Pixmap ID of original Pixmap on failure.
131
133 set_window_background_and_free() will set window's background to
134 specified Pixmap, Then refresh window contents so that background
135 is drawn by the server, flush all the requests to force it to be sent
136 to server to be processed as fast as possible.
137
139 After Window's background has been set to Pixmap - X server makes
140 hidden copy of this Pixmap for later window refreshing. As the result
141 original Pixmap is no longer needed and can be freed to conserve
142 resources.
143
145 Source :
146 Pixmap
147 set_window_background_and_free( Window w, Pixmap p )
148 {
149 #ifndef X_DISPLAY_MISSING
150 if( p != None && w != None )
151 {
152 XSetWindowBackgroundPixmap( dpy, w, p );
153 XClearWindow( dpy, w );
154 XFlush( dpy );
155 XFreePixmap( dpy, p );
156 p = None ;
157 }
158 #endif /* X_DISPLAY_MISSING */
159 return p ;
160 }
161
164 void wait_closedown( Window w );
165
167 w - ID of the window from which to wait for events.
168
169
171 User action requesting window to be closed is generally received
172 first by Window Manager. Window Manager is then handles it down to
173 the window by sending it ClientMessage event with first 32 bit word
174 of data set to the value of WM_DELETE_WINDOW Atom.
175 Accordingly, all client has to do is wait for such event from X server
176 and, when received, it should destroy its window and generally exit.
177
179 It is recommended that XFlush() is issued right after XDestroyWindow()
180 as Window Manager itself may attempt to do something with the window
181 until it receives DestroyNotify event.
182
184 ICCCM, Window
185
187 Source :
188 void
189 wait_closedown( Window w )
190 {
191 #ifndef X_DISPLAY_MISSING
192 if( dpy == NULL || w == None )
193 return ;
194
195 XSelectInput (dpy, w, ( StructureNotifyMask |
196 ButtonPressMask|
197 ButtonReleaseMask));
198
199 while(w != None)
200 {
201 XEvent event ;
202 XNextEvent (dpy, &event);
203 switch(event.type)
204 {
205 case ClientMessage:
206 if ((event.xclient.format != 32) ||
207 (event.xclient.data.l[0] != _XA_WM_DELETE_WINDOW))
208 break ;
209 case ButtonPress:
210 XDestroyWindow( dpy, w );
211 XFlush( dpy );
212 w = None ;
213 break ;
214 }
215 }
216 XCloseDisplay (dpy);
217 dpy = NULL ;
218 #endif
219 }
220
221
222
2233rd Berkeley Distribution AfterStep v.2.2.6 common(1)