Debian Codegraph @

docs/README.kstartupinfo

raw
1 Application startup notification
2 Lubos Lunak <[email protected]>
3 --------------------------------
4 --------------------------------
5
6
7 When a new application is started in KDE, together with it a startup
8 notification is sent, which is used to show a startup entry in taskbar,
9 the busy icon next to the cursor and put the window of the started app
10 on correct desktop.
11 This application startup notification ( ASN for short in the following
12 text ) usually works fine without problems, but some applications and
13 some special cases may need special handling.
14 Right now, this is only an internal KDE standard, but since a toolkit
15 support would improve the results a bit, I'll try to discuss this
16 on http://www.freedesktop.org .
17
18
19 Starting apps with ASN :
20 -------------------------
21
22 When an application is started from the K-Menu or the minicli, and from other
23 places, ASN is sent automatically for it, assuming a matching .desktop file
24 is found for the starting application. Application without a .desktop file
25 don't get ASN ( this may change, but it's unlikely as it creates too many
26 ASNs which will stay too long until a timeout ). For improving the quality
27 of ASN and reducing the number of ASNs that don't detect when the application
28 has started, some .desktop file entries may be helpful ( see below ).
29 If you want to start an application in your code, prefer using KRun or
30 KApplication::startServiceByXXX() calls. Classes like KProcess don't create
31 ASN, so if you need to use it, you have to send it manually ( only in case
32 ASN is useful in this case, it shouldn't be sent e.g. for system processes ).
33
34
35 .desktop files :
36 -----------------
37
38 These following .desktop file entries affect ASN :
39
40 X-KDE-StartupNotify=<bool>
41 - if true, this app/service will get app startup notify
42 - if false, this app/service will _not_ get app startup notify
43 - if not set
44 - if it's service, it will _not_ get app startup notify
45 - if it's app, it will get app startup notify, but
46 X-KDE-WMClass will be assumed to be "0" ( non-compliant )
47 X-KDE-WMClass=<string>
48 - if set, and it's different from "0" ( without quotes ), this
49 is the WMClass value for startup notification
50 - if it's "0" ( without quotes ), such app is considered non-compliant,
51 and the startup notification will stop
52 - either if its windows is correctly detected using the default
53 WMClass value ( the name of the binary )
54 - or if a window is mapped that is not recognized ( doesn't have
55 neither _KDE_STARTUP_ID nor _NET_WM_PID property /*CHECKME*/),
56 it's assumed this window belongs to the started app;
57 the start-on-desktop feature won't work then too
58 - if not set, it defaults to the binary name of the app ( ok for most apps,
59 including KDE ones )
60 - to get the WMCLASS value for any app, run 'xprop' and click on the app's
61 window, WMCLASS value for this app should be any of the strings listed
62 in the WM_CLASS property ( it's usually the same as the name of the
63 app's binary file, in such case it doesn't need to be explicitly set )
64 MapNotify=<bool>
65 - this key is obsolete
66 - true is equivalent to X-KDE-StartupNotify=true and no X-KDE-WMClass set
67 - false is equivalent to X-KDE-StartupNotify=true and X-KDE-WMClass=0
68 - many .desktop files in KDE ( especially in kdebase/kappfinder )
69 seem to have MapNotify=false even though it's not needed, this
70 needs to be checked and replaced by the needed X-KDE-* values,
71 often just X-KDE-StartupNotify=true should be enough
72
73 The best way to check if the entries are set correctly is to start
74 the application and switch to other desktop. If the startup notification
75 disappears and the application appears on the desktop on which it was
76 started, it's correct ( with X-KDE-WMClass=0, the start-on-desktop
77 feature may not work ).
78
79 Ideally, every .desktop file should have X-KDE-StartupNotify set to the correct
80 value, and for apps which need it also X-KDE-WMClass should be set. This
81 sometimes gives slightly better behavior than when these entries are not set.
82
83
84 The KStartupInfo classes :
85 --------------------------
86
87 In some cases, or if you are interested in getting the ASN information, you
88 have to use the KStartupInfo classes in kdelibs/kdecore.
89
90 Receiving the application startup notification information :
91 ------------------------------------------------------------
92
93 Create an instance of class KStartupInfo and connect to its slots, they
94 will be emitted whenever a ASN info is received.
95 The clean_on_cantdetect argument to the constructor means whether all
96 ASN info for non-compliant apps should be removed when a window is mapped
97 which cannot be identified ( it's not possible to say if it belong to one
98 of the starting applications or not ). If the argument is true, it is
99 assumed that the window does belong to one of the starting applications,
100 and all ASN info for non-compliant apps must be removed, otherwise the ASN
101 info would timeout ( e.g. kdesktop sets it to true, otherwise the busy
102 icon would sometimes stay for too long, which is oftern annoying ).
103 On the other hand, KWin, which maps the first window of the starting apps
104 to the given virtual desktop, sets it to false, because there's no visual
105 representation and if a window for a starting non-compliant application is
106 detected later, it still will be successfully places on the correct virtual
107 desktop.
108 Note that the ASN info is often send in several messages, and the slots
109 will be therefore emitted several times, with the updated info ( e.g. the
110 binary name or PID is not know from the beginning ).
111
112 Sending the application startup notification information :
113 ----------------------------------------------------------
114
115 Before an application is started, ASN info for it must be sent ( unless
116 it's done by classes like KRun ). See e.g. KRun sources for details.
117 During the starting of the application, the info may need some updating
118 ( e.g. right after starting the app, the PID with hostname may be sent,
119 or a PID change when KUniqueApplication forks into background ).
120 When it's detected that the started process exited, it an ASN info
121 about the finished process should be sent. Since the application may
122 have forked into background, the finish info should include the PID
123 and hostname, and the notification will be stopped only if there's
124 no other PID for it. On the other hand, if you simply really need
125 to stop ASN, send only the identification ( KStartupInfo::sendFinish()
126 with only KStartupInfoId argument ).
127
128
129
130 Implementation details :
131 ------------------------
132
133 The ASN info data is sent using X ClientMessages as text ( see below ),
134 this is mainly in hope also non-KDE people will start using it, and
135 they wouldn't be very happy with DCOP.
136 Before starting an application, and environment variable called
137 KDE_STARTUP_ENV is added to it's environment, and it's set to unique
138 identifier of its startup notification, or "0" for disabled ASN.
139 Ideally, the application should read it, and set a window property
140 called _KDE_STARTUP_ID ( type XA_STRING ) at least on its first mapped
141 toplevel window to this value. It should also unset it, so it doesn't get
142 propagated to other applications started from it. It should also
143 update the ASN info when necessary, e.g. when KUniqueApplication
144 forks into background, it sends the PID change. That's how compliant
145 applications should work, and this support for ASN should be provided
146 by toolkits. All KDE application should be compliant by now, since
147 kdelibs do all the necessary things. The KDE_STARTUP_ENV variable
148 is read and unset in KApplication constructor, and _KDE_STARTUP_ID
149 is set on every toplevel window in KApplication::setTopWidget().
150 However, majority of applications aren't compliant now, and even
151 if I succeed making this thing a standard ( part of NETWM_SPEC
152 or whatever ), there still will be old applications that won't behave
153 this way. Not unsetting KDE_STARTUP_ENV is not a big problem, since
154 the ASN for its value will usually timeout, and when the app starts
155 a new application, this ASN identification value will get reused without
156 problems. The other problem is detecting, which newly mapped windows
157 belong to which starting application. If a newly mapped window doesn't
158 have _KDE_STARTUP_ID property, the code tries to read its _NET_WM_PID
159 property, and if it's set, it tries to match it ( together with
160 WM_CLIENT_MACHINE ) with PIDs of all ASN infos. And if the window
161 doesn't have even the _NET_WM_PID property, WM_CLASS property is used
162 then. It's usually set to two strings, and at least one of them is
163 usually the binary name of the application, so it's converted
164 to lowercase and compared. For applications, where such comparison
165 would fail, the X-KDE-WMClass .desktop file entry should be set
166 to the correct WMClass value ( e.g. for XEmacs, the binary name
167 is 'xemacs', but WM_CLASS is 'emacs', 'Emacs', so its X-KDE-WMClass
168 in its .desktop file should be set to 'emacs' - the case doesn't
169 matter ).
170 The ASN identification string must be a unique string for every ASN.
171 In KStartupInfo class, it's created as 'hostname;tm.sec;tm.usec;pid',
172 tm being the current time. If the identification string is set to "0",
173 it means no ASN should be done ( e.g. for things like kio_uiserver,
174 which shouldn't get ASN ). Empty identification string means the same
175 like "0", except for the call to KStartupInfoId::initId(), where it means
176 to create a new one.
177
178
179 Format of the text messages :
180 -----------------------------
181
182 There are 3 types of messages :
183 - new: message
184 - this message announces that a new application is being started,
185 if there is not ASN info for this ASN identification, it should be
186 updated, otherwise it will be created
187 - the text of the message starts with 4 characters 'new:', followed
188 by the text entries ( see below )
189 - change: message
190 - this message is like new: message, but it's only for updating existing
191 ASN info, if there's no ASN info for the given identification, it won't
192 be created. This is used e.g. in KUniqueApplication when it forks
193 into background and sends info about the PID change - it should update
194 any existing ASN info, but mustn't create a new one, otherwise there
195 could appear ASN even for applications which shouldn't have ASN
196 - the text of the message starts with 4 characters 'change:', followed
197 by the text entries ( see below )
198 - remove: message
199 - this message is sent for stopping ASN with the given identification.
200 If the only item in the message is the identification string, the ASN
201 info should be removed. If there are also the PID and HOSTNAME entries
202 ( see below ), the matching ASN info should be only removed if this
203 given PID is the only PID for it ( in this case, the identification
204 string may be omitted ).
205 - the text of the message starts with 4 characters 'remove:', followed
206 by
207 - only ID entry
208 - only ID, PID and HOSTNAME entries
209 - only PID and HOSTNAME entries
210
211
212 Text entries in the messages :
213 ------------------------------
214
215 Every entry is of the form <name>=<value>. Value may be either a number
216 or a string. If the string contains spaces, it must be quoted ("), all
217 backslashes and quotes (") must be escaped by backslashes. If this ever
218 becomes more than an internal KDE standard, non-standard entry names should
219 start with an underscore.
220
221 Entries :
222
223 - ID - string
224 - the identification string of the startup notification
225 - it must be present in all messages except for the remove:
226 message with only PID and HOSTNAME
227 - BIN - string
228 - the binary name of the starting application
229 - usually used as a fallback value if WMCLASS is not present
230 - e.g. 'kcontrol'
231 - NAME - string
232 - the name of the starting application
233 - usually used only for displaying it when indicating that
234 the application is starting
235 - e.g. 'Control Center'
236 - ICON - string
237 - the icon for this startup notification
238 - it should be handled like the Icon= entry in .desktop files
239 - e.g. 'kcontrol'
240 - DESKTOP - number
241 - the virtual desktop on which the application should appear
242 - if the application's first window has _NET_WM_DESKTOP already
243 set when the window is mapped, it shouldn't be changed
244 - WMCLASS - string
245 - the WMCLASS value used for matching newly mapped windows
246 of non-compliant applications
247 - useful only if it's different from the binary
248 name of the application
249 - PID - number
250 - the PID of a process that belongs to this startup notification
251 - there may be several PIDs for one notification
252 - value 0 is also valid, meaning that there's a process
253 with unknown PID for this notification ( is used e.g.
254 by kfmclient when it sends a DCOP message to already running
255 konqueror instance to create a new window and exits immediately,
256 without adding the zero PID to the notification, process
257 that started kfmclient could detect it exited and would send
258 a remove: message for the notification with kfmclient's PID,
259 which would cause the notification to stop if there wasn't also
260 PID=0 for it
261 - HOSTNAME - string
262 - the hostname of the machine on which the application is being
263 started
264 - this is used together with the PID entry
265
266 --------------------
267
268 Well, I guess that's all. The KDE2.2 release will show if the users like it
269 or not ( it's quite good IMHO, even though there are probably some minor
270 details to fix or improve ). The only big thing remaining is to make also
271 non-KDE people agree on using something like this. My first attempt
272 https://listman.redhat.com/pipermail/xdg-list/2001-May/000083.html
273 didn't get much attention, but now that there's a working implementation,
274 I hope it will get better, when I try again sometime in the future.
275
276
277
278 Lubos Lunak <[email protected]>
279