Debian Codegraph @

doc/startup-notification.txt

raw
1 Startup notification protocol
2 ===
3
4 This document specifies a mechanism allowing a desktop environment to
5 track application startup, to provide user feedback and other
6 features.
7
8 Version: 0.1
9 Revised: October 20, 2002
10 Authors: Lubos Lunak, Havoc Pennington
11
12 Terms
13 ===
14
15 Launch: a "startup event" such as opening a new window, opening a new
16 application, or adding a panel applet. Note that the
17 launch may or may not involve creating a new UNIX process.
18 Launcher: code which starts up a launch
19 Launchee: code which is started up by the launcher
20
21 X Messages
22 ===
23
24 "X messages" are a mechanism for sending text strings between X
25 clients.
26
27 To send a string as an X message, a client does the following:
28
29 - Creates an X window to be used to identify the message
30 uniquely. This window need not be mapped, and may be
31 a child of any window.
32
33 - Interns atoms type_atom and type_atom_begin indicating
34 the type of message.
35
36 - Decides on a target_xwindow; this is the root window
37 for "broadcast" messages, or a specific client's window.
38
39 - Send a series of client messages to the target X window, where each
40 client message contains a portion of the string. The client
41 messages should have the window field set to the X window
42 identifying the message, the format field set to 8, and
43 the message_type field set to the type of message, type_atom_begin
44 for the first client message and type_atom for any following client
45 messages.
46
47 The last byte used in the last client message must be nul, and no
48 intermediate bytes may be nul. The nul byte identifies
49 the end of the message.
50
51 Client messages must be sent to the chosen target_xwindow, with the
52 event mask PropertyChangeMask.
53
54 (FIXME this is a bad choice of mask, as we get a bunch of annoying
55 PropertyNotify events; but which mask would be better?)
56
57 Attachment "A" contains example code.
58
59 - Destroys the unique X window used to identify the message.
60 The window can be destroyed immediately, it is only used
61 for its window ID.
62
63 Implementations may impose a maximum length of message they are
64 willing to accept. Typically this length will be reasonably low,
65 perhaps 4K of data.
66
67 Key-value strings
68 ===
69
70 The specific strings sent during startup notification encode a message
71 type, followed by a list of key-value pairs. Here is an example:
72
73 new: NAME="Hello World" PID=252
74
75 A string listing key-value pairs works as follows:
76
77 - the entire string must be valid UTF-8. Invalid strings should be
78 discarded as corrupt, as accepting bad data leads to
79 interoperability problems. (Learn from web browsers.)
80
81 Although the string is UTF-8, parsing is specified in terms of
82 bytes not characters in the below specification.
83
84 - all bytes up to the first ':' byte indicate the type of the
85 message. If the message contains no ':' byte it should be discarded
86 as corrupt.
87
88 - To find the start of a key, the ':' byte delimiting the message
89 type must be skipped. Any space (' ') bytes following it must also
90 be skipped. (Other kinds of whitespace must not be skipped.) The
91 first non-' ' byte after the ':' byte is the start of the first
92 key.
93
94 - All bytes until the next '=' byte form the name of the
95 key. The '=' byte should be discarded, as it delimits the
96 key from the value.
97
98 - Parsing of the value begins with the byte immediately following the
99 '=' byte. The value is parsed
100 as follows.
101
102 There are two dimensions, "escaped" and "quoted", creating 4
103 states:
104
105 - escaped = TRUE quoted = TRUE
106 . the current byte is appended literally, and the escaped
107 flag is set to FALSE
108
109 - escaped = TRUE quoted = FALSE
110 . the current byte is appended literally, and the escaped
111 flag is set to FALSE
112
113 - escaped = FALSE quoted = FALSE
114 . if the current byte is a double quote '"' it is
115 discarded, and the quoted flag is set to TRUE
116 . if the current byte is a backslash '\', it is
117 discarded, and the escaped flag is set to TRUE
118 . if the current byte is a space ' ' byte or nul byte,
119 the end of the value has been reached
120 . any other byte, INCLUDING tabs, newlines, etc., must be
121 appended literally.
122
123 - escaped = FALSE quoted = TRUE:
124 . if the current byte is a double quote '"'
125 it is discarded, and the quoted flag is
126 set to FALSE
127 . if the current byte is a backslash '\'
128 it is discarded, and the escaped flag
129 is set to TRUE
130 . otherwise the current byte is appended literally
131
132 If a nul byte is seen in a state other than escaped = FALSE
133 quoted = FALSE, it is an error, and the message should be discarded
134 as corrupt.
135
136 Note that the escaping here is simpler than either C string literal
137 escaping, or shell quoting. Unlike C string literals, "\n" means
138 "the letter n," not "newline"; unlike quoted shell strings, "\e"
139 means "the letter e," not "backslash followed by the letter e."
140
141 Note that an empty string can be represented by simply not
142 including a value before the first whitespace, as in FOO:
143 FOO= NAME=Hello
144 or by empty quotes as in BAR:
145 BAR="" NAME=Hello
146
147 - Once the end of the value has been reached, any space (' ') bytes
148 should be skipped. The first non-' ' byte is the first byte of the
149 next key.
150
151 Note that keys are case-sensitive, Foo and FOO are different keys.
152
153
154 Startup notification
155 ===
156
157 The startup notification protocol involves sending X messages with the
158 message_type atom _NET_STARTUP_INFO_BEGIN/_NET_STARTUP_INFO to the
159 root window. In multihead setups, the messages should go to the root
160 window of the X screen where the launchee application is being
161 launched.
162
163 As a general convention, any key-value pairs in startup notification
164 messages that aren't understood by a given client should be ignored by
165 that client. Also, any keys or message types not documented here must
166 be prefixed by the two bytes "X-" as in "X-myproperty" or
167 "X-mymessage".
168
169 All messages in the startup notification protocol refer to a "startup
170 sequence"; a "startup sequence" reflects a single launch event.
171
172 Here are the message types ("message types" here means the type at the
173 beginning of the message string, not the type of the X message):
174
175 new: message indicating that a new startup sequence has been
176 initiated. The key-value pairs in this message indicate the
177 properties of the startup sequence. If this startup sequence
178 already exists, "new:" message is equivalent to "change:"
179 (i.e. the values are updated instead of creating a new
180 startup sequence).
181
182
183 change: message changing a startup sequence. Clients should update
184 information about the matching startup sequence to the newly
185 provides information. "change" messages contain
186 a subset of the keys allowed in a "new" message. Not all
187 attributes of the startup sequence are allowed to change
188 over time.
189
190 "change:" messages not be taken as a "new:" message,
191 i.e. they should not cause any feedback or similar.
192
193 If a client has not seen a "new:" message for the same sequence,
194 then it should remember the information for later use in case
195 a "new:" message comes later. "change:" messages without
196 a following "new:" message can be discarded after a reasonable
197 timeout (>= 1 minute). Rationale: The application
198 may want to send certain information like timestamp or description
199 first, before handling control to library code deciding
200 if there should be actually any feedback for the launch.
201
202
203 remove: message ending a startup sequence. Once this message
204 has been seen for a given sequence, any further
205 messages referring to the sequence should be ignored.
206
207 All messages must include these keys:
208
209 ID
210
211 uniquely identifies a startup sequence; should be some globally
212 unique string (for example, hostname+pid+"_TIME"+current time).
213 The string should be in the form of <unique>_TIME<timestamp>,
214 where the timestamp is the X server timestamp of the user
215 action that caused the launch. See the TIMESTAMP key
216 for details.
217
218 The following keys are required in a "new" message and may be included
219 in either a "new" or a "changed" message:
220
221 NAME
222
223 some human-readable name of the item being started;
224 for example, "Control Center" or "Untitled Document";
225 this name should be localized.
226
227 SCREEN
228
229 the X screen number the startup sequence is on
230
231 The following keys may be provided optionally in either a "new" or a
232 "changed" message:
233
234 BIN
235
236 name of the executable being started, argv[0]
237
238 ICON
239
240 a string to be interpreted exactly as the "Icon" field
241 in desktop entries is interpreted.
242
243 LAUNCHED_BY
244
245 identification of the top-level window in which the launch was initiated.
246 The value is the X window ID of the window.
247
248 DESKTOP
249
250 the desktop on which the application should appear,
251 counting from 0, as in _NET_WM_DESKTOP. However,
252 this value should never override a _NET_WM_DESKTOP
253 property set on window that's being mapped.
254 This desktop is relative to the screen provided by
255 the SCREEN key.
256
257 TIMESTAMP
258
259 X server timestamp of the user action that caused this
260 launch. For example window manager that doesn't allow
261 stealing of focus by newly mapped windows while the user
262 works in an application can use this timestamp for windows
263 that have matching _NET_STARTUP_ID property if they don't
264 have any _NET_WM_USER_TIME property set or if it's older.
265 See the description of _NET_WM_USER_TIME in the WM spec
266 for details.
267
268 This key is obsoleted by including the timestamp directly
269 in the ID field.
270
271 DESCRIPTION
272
273 a short description suitable for display in a dialog that
274 indicates what's happening. For example "Opening document
275 Foo" or "Launching KWord" - the description should be in
276 "foo-ing whatever" format, describing the current status.
277
278 WMCLASS
279
280 a string to match against the "resource name" or "resource
281 class" hints. If this key is present, the launchee will most
282 likely not send a "remove" message on its own. If the
283 desktop environment detects a toplevel window mapped with
284 this name or class, it should send a "remove" message for
285 the startup sequence. Note that the class hint is in
286 Latin-1, so the value of this key must be converted to
287 Latin-1 before strcmp'ing it with the window class/name.
288 (Though in all known cases only ASCII is involved so it
289 doesn't matter.)
290
291 SILENT
292
293 a boolean (1/0) value. When set to 1, there should be
294 no visual feedback. This can be used to suspend
295 the visual feedback temporarily, e.g. when
296 application shows a dialog during its startup before
297 mapping the main window. Another use is for launch
298 sequences for applications that are neither compliant
299 nor their WMClass is known, but which should preferably
300 have their window mapped on the desktop specified by
301 the value of DESKTOP.
302
303 APPLICATION_ID
304
305 When launching an application using a .desktop file from
306 the normal application paths (see desktop file specification),
307 this should be basename of the .desktop file.
308 For example: "foo.desktop".
309
310 When launching a .desktop file NOT in the paths, this should
311 be an absolute path to the .desktop file.
312
313 Some details of the startup sequence:
314
315 - "new" and "change" messages are sent by the launcher code
316
317 - the launchee code is responsible for sending a "remove"
318 message to end the launch sequence, unless the WMCLASS
319 key was set.
320
321 - the "new" message must be the first message. Other message
322 types should be ignored by all clients unless those clients
323 have seen a "new" message with the same ID.
324
325 - "change" messages can be sent at any time between "new" and
326 "remove"
327
328
329 Communicating from a launcher process to a launchee process
330 ===
331
332 To communicate the startup sequence information from a launcher
333 process to a launchee process, when possible an environment variable
334 should be used:
335
336 DESKTOP_STARTUP_ID
337 value of the "ID" field in the "new" message
338
339 It is suggested to unset this environment variable in the launchee
340 as soon as it's read, to avoid possible reuse by some process started
341 later by launchee.
342 Mechanisms other than the environment variable may be used as well, as
343 long as they are reliable. The environment variable is only used when
344 the launchee code is in a process started by the launcher code; if
345 they are in the same process the environment variable may not be
346 relevant.
347
348 Desktop entry spec extensions
349 ===
350
351 StartupNotify=BOOLEAN
352
353 If true, it is KNOWN that the application will send a "remove"
354 message when started with the DESKTOP_LAUNCH_ID environment variable
355 set.
356 If false, it is KNOWN that the application does not work
357 with startup notification at all (does not shown any window, breaks
358 even when using StartupWMClass, etc.).
359 If absent, a reasonable handling is up to implementations (assuming false,
360 using StartupWMClass, etc.).
361
362 StartupWMClass=STRING
363
364 If specified, it is KNOWN that the application will map at least one
365 window with the given string as its WM class or WM name hint.
366
367 EWMH spec extensions
368 ===
369
370 _NET_STARTUP_ID, UTF8_STRING
371
372 The ID used for the startup sequence for the window. If set
373 on a group leader window, applies to all application windows
374 in that group that do not set their own _NET_STARTUP_ID.
375
376 If a new value for the property is set, the window manager
377 should update the window's status accordingly (update its virtual
378 desktop, etc.).
379
380
381 Launchee failures
382 ===
383
384 The launcher process is responsible for detecting launchee failures
385 such as a crash and should end the launch sequence in such case.
386 In case launchee fails to end the launch sequence, clients should
387 treat the launch sequence as ended withing a reasonable time.
388
389
390 A. Sample code to send X message
391 ===
392
393 This code omits creation/destruction of "xwindow" which is the unique
394 identifier window for the message. It should be created just before
395 this code and destroyed just after.
396
397 XEvent xevent;
398 const char *src;
399 const char *src_end;
400 char *dest;
401 char *dest_end;
402
403 xevent.xclient.type = ClientMessage;
404 xevent.xclient.message_type = type_atom_begin;
405 xevent.xclient.display = xdisplay;
406 xevent.xclient.window = xwindow;
407 xevent.xclient.format = 8;
408
409 src = message;
410 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
411
412 while (src != src_end)
413 {
414 dest = &xevent.xclient.data.b[0];
415 dest_end = dest + 20;
416
417 if (src == message)
418 {
419 *dest = '\0';
420 ++dest;
421 }
422
423 while (dest != dest_end &&
424 src != src_end)
425 {
426 *dest = *src;
427 ++dest;
428 ++src;
429 }
430
431 XSendEvent (xdisplay,
432 target_xwindow,
433 False,
434 PropertyChangeMask,
435 xevent);
436
437 xevent.xclient.message_type = type_atom_begin;
438 }
439
440 Change history
441 ===
442
443 Changes since 0.1:
444
445 - TIMESTAMP field is obsoleted by including the timestamp directly in the ID.
446 - data from "change:" messages should be used even if they precede the matching "new:" message
447 - added LAUNCHED_BY
448 - Explicitly mention that updating the _NET_STARTUP_ID property on a window should trigger
449 window manager's actions for the new startup notification again.