After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 115650 - Support _NET_WM_USER_TIME
Product: gtk+
Classification: Platform
Component: Backend: X11
Other Linux
: High major
: ---
Assigned To: gtk-bugs
Depends on:
Reported: 2003-06-21 03:10 UTC by Havoc Pennington
Modified: 2011-02-04 16:17 UTC
See Also:
GNOME target: 2.8.0
GNOME version: 2.7/2.8

support USER_TIME (4.32 KB, patch)
2003-12-07 19:55 UTC, Rob Adams
none Details | Review
old version of patch; shown only so I can make reference to it (7.19 KB, patch)
2004-01-23 19:13 UTC, Elijah Newren
none Details | Review
Patch to support _NET_WM_USER_TIME (do-not-focus-on-map hint) (14.15 KB, patch)
2004-01-23 19:15 UTC, Elijah Newren
none Details | Review
Patch to support _NET_WM_USER_TIME (18.45 KB, patch)
2004-02-17 23:44 UTC, Elijah Newren
none Details | Review
Corrected patch (18.41 KB, patch)
2004-02-29 01:52 UTC, Elijah Newren
none Details | Review
Remove asserts sanely (19.81 KB, patch)
2004-03-05 00:07 UTC, Elijah Newren
needs-work Details | Review
Patch with API removed (10.17 KB, patch)
2004-04-14 18:20 UTC, Elijah Newren
none Details | Review
Corrected patch, no PROP_FOCUS_ON_MAP constant (10.01 KB, patch)
2004-04-14 21:57 UTC, Elijah Newren
none Details | Review
fix compilation error (2.10 KB, patch)
2004-04-23 04:23 UTC, Elijah Newren
none Details | Review
API portion of the patch (16.96 KB, patch)
2004-04-29 21:14 UTC, Elijah Newren
accepted-commit_now Details | Review
Patch to make sure _NET_WM_USER_TIME is updated (3.23 KB, patch)
2004-08-19 21:29 UTC, Elijah Newren
none Details | Review

Description Havoc Pennington 2003-06-21 03:10:24 UTC
_NET_WM_USER_TIME is in the CVS EWMH, we need to implement it 
and/or get the spec changed such that we want to implement it.
Comment 1 Rob Adams 2003-12-07 19:55:50 UTC
Created attachment 22194 [details] [review]
support USER_TIME
Comment 2 Rob Adams 2003-12-07 20:01:25 UTC
here's a first crack at a patch to support USER_TIME in gdk.  This
seems to work well for most GTK apps, but for some reason, though,
this doesn't work with gnome-terminal.  I haven't had a chance to dig
through gnome-terminal code to figure out why, but I figured Havoc
would probably know what sort of weird black magic gnome-terminal is
doing to bypass this.  Probably something to do with embedding widgets
in toplevel windows behind GDK's back.

The patch adds a new function to the API:
gdk_window_set_user_time_hint which does just that.

It's entirely possible that apps like gnome-terminal will just have to
 manually call set_user_time_hint as appropriate.
Comment 3 Owen Taylor 2003-12-09 23:43:18 UTC
As I said in:

while I don't particularly *like* _NET_WM_USER_TIME, I can't think
of a better way of doing it; since I "gave the approval" there,
I think we need to implement it.

In terms of this patch:

 * The patch only implements half of the _NET_WM_USER_TIME
   scheme - it doesn't set it on newly mapped windows, which
   is the whole point. The default _NET_WM_USER_TIME value
   for newly mapped windows, should be the last 

 * User time also needs to be updated on XInput events.

 * gdk_window_set_user_time_hint() shouldn't (IMO) be in the
   cross-platform API because it's never going to make sense
   on anything but X11. 

 * I don't actually think there is anything special going
   on in the vte widget, so that needs to be debugged
   before we add the patch.

The API I'd like to see is:

 void gdk_x11_window_set_user_time (GdkWindow *window,
                                    guint32    timestamp);
  void gdk_window_set_focus_on_map (GdkWindow *window,
                                   gboolean   should_focus);

 void gtk_window_set_focus_on_map (GtkWindow *window,
                                   gboolean   should_focus);

 Property GtkWindow::focus-on-map

Where the focus-on-map settings default to TRUE and are documented
as "hints"  - should_focus = FALSE says that that focus on map
isn't useful. focus-on-map should be turned off for windows
that aren't triggered interactively, such as popups from network

The gdk_window and gtk_window docs, since they are cross-platform,
should not reference X11 specific details, except possibly
as "On X.."

Stubs need to be added in the win32 and linux-fb buffers for the
gdk_window_set_focus_on_map(), though you'll need to file another
bug against the win32 component to actually imnplement the
functionality (if relevant)
Comment 4 Rob Adams 2004-01-14 21:49:30 UTC
Sorry I should have been more explicit when I first posted the patch
that I hadn't yet implemented the part about setting the hint on
initial map.

Another thing that needs to be implemented is keeping track of a sort
of global "last user input".  I'm not sure what the best way to do
that in gdk would be.  Should we use the most recent user_time of the
parent window, or use a global variable somewhere to keep track of it?
Comment 5 Elijah Newren 2004-01-22 15:48:44 UTC
Just thought I'd post to say I'm working on this bug.  I was able to
get Rob's patch to work for gnome-terminal and all other gtk+
applications I tried which were linked against my modified gtk+.  (I
also had some issues with gnome-terminal too at first, but I think
they all turned out to be things like me running the wrong
gnome-terminal, not closing all gnome-terminals before opening a new
one to test, etc;  I believe Rob may have just been experiencing
similar problems).  I also have the hint for new mapped windows
implemented and I found it to work when I tested it with my current
patch against Metacity (see bug 118372 for more on that).

I'll post a patch sometime soon and also bring up some
questions/issues related to it...  
Comment 6 Elijah Newren 2004-01-23 19:13:04 UTC
Created attachment 23681 [details] [review]
old version of patch; shown only so I can make reference to it
Comment 7 Elijah Newren 2004-01-23 19:15:11 UTC
Created attachment 23682 [details] [review]
Patch to support _NET_WM_USER_TIME (do-not-focus-on-map hint)
Comment 8 Elijah Newren 2004-01-23 19:27:32 UTC
I've attached two patches.  The first is just so I can reference it
(and was quite similar to Rob's patch), the second is a working patch.
  I have several comments/questions :

 * My gtk patch was based heavily off of Matthias' patch for bug
   64613 since it was highly similar.  However, do I really need all
   the get/set functions? I assumed yes, since get/set functions exist
   even for default size of the window.
 * Owen only mentioned a GtkWindow::focus-on-map variable; isn't
   a GdkWindow::focus-on-map variable needed too? (I didn't see how to
   implement the patch without one.)
 * I don't understand why Rob tried to update _NET_WM_USER_TIME in
   both Metacity and gtk/gdk.  I would think that one would only want
   to do it in Metacity, because the updating in gtk would only work 
   for gtk apps (and doing it in both is redundant).
 * I don't understand Rob's comment about a global variable either.
 * The KeyRelease stuff in my first patch (and in Rob's patch) seems
   to be against the wm-spec.  But I don't quite understand why the 
   spec states to not update on KeyRelease events, and updating at 
   those times would seem to make sense to me.  Comments?
 * I'm not sure how to handle XInput events.  I took a wild stab at it
   in my first patch, but I have no idea whether it's even close to 
   being correct.

I'm adding the PATCH and security keywords.  (Note that windows being
focused upon launch can cause apps such as GAIM to end up receiving
and sending a typed password.  Telsa report on #gnome that she got
Alan's password accidentally once that way.  Also, error dialogs could
be missed if the user hits the enter key right when it appears)

Also, I'm trying to keep track of all the issues (there were many that
came up, mostly related to Metacity, and I was having a hard time
keeping track of links to all the appropriate locations) at  That
may be useful to someone trying to track down the wm-spec files and
all the issues I'm thinking of.
Comment 9 Elijah Newren 2004-01-24 05:53:13 UTC
Let me just note that Rob explained to me why he had the gtk updates
of _NET_WM_USER_TIME in bug 118370; I'll add that back into my patch
and attach it here.  (I still don't understand the global variable
comment, but I've asked him to explain more; hopefully that will help
me understand what I'm missing.)
Comment 10 Soren Sandmann Pedersen 2004-02-17 21:47:05 UTC
I don't think this is going to make 2.4, but moving to 2.4 API because
the proposed patch adds API.
Comment 11 Elijah Newren 2004-02-17 23:44:48 UTC
Created attachment 24500 [details] [review]
Patch to support _NET_WM_USER_TIME
Comment 12 Elijah Newren 2004-02-17 23:51:31 UTC
I've had this newer version of the patch for a couple weeks, but I've
been sidetracked by school work and some stuff I was doing with the
bugsquad.  Anyway, I just updated the patch to apply against recent
CVS.  Differences between it and my previous patch:
  - Reincorporates setting of the timestamp upon Key/Button Press
  - Updates the timestamp upon XInput events
  - Has a 'global' user_time for last user input

I was not sure which XInput events should update the user time, so I
simply updated on all of them.  Also, I didn't know if XInput
Key/Button Release events could cause similar problems to normal
Key/Button Release events so I also updated the time for those.  

Also note that this patch has some extra asserts that were mainly
meant for debugging, but they can be removed if/when some form of this
patch gets approved.

I believe this patch is everything that is needed as far as gtk+ goes
for _NET_WM_USER_TIME support.  I've tested it with my
startup-notification and metacity patches and it works well for me. 
[My metacity patch is still missing two things (grabbing keypresses
and not raising windows on map unless they're focused as well) so I
haven't yet posted it (or my updated startup notification patch) to
bug 118372.  So if someone else wants to test it, see the patches on
my website that I posted a link to earlier.]

Comment 13 Matthias Clasen 2004-02-18 09:59:29 UTC
More interesting than testing with metacity would be testing with kde, 
imo. KDE already supports _NET_WM_USER_TIME, right ?
Comment 14 Elijah Newren 2004-02-18 16:32:43 UTC
Ah, good point.  I guess I need to download and compile the latest KDE...
Comment 15 Elijah Newren 2004-02-27 05:45:53 UTC
Okay, I've now completed the testing under KDE 3.2.  Everything that I
am able to test under Kwin with this gtk+ patch works.  Since I can't
test XInput stuff, however, that does leave the possibility that it
could be wrong.  Is anyone else able to test XInput events?  Anyone
have comments on the saneness of the patch?
Comment 16 Elijah Newren 2004-02-27 14:13:26 UTC
Ooops, I forgot to test one of the edge cases.  That one fails, which
means that these lines from gdkwindow-x11.c in the patch

      GDK_DISPLAY_X11 (screen_x11->display)->user_time);

are suspect.  They work in the vast majority of cases but fail in one
particular test.  So either Rob and Lubos had a communication
disconnect, or else I didn't understand Rob's explanations (which is
much more likely).  I'll go figure out what the correct thing to do
is, make an updated patch, test it, and post it here.
Comment 17 Rob Adams 2004-02-27 20:46:03 UTC
Note that you should NOT set the USER_TIME hint if you don't have a
value for it.  Notably, if the application has just been launched and
has had no user interaction, the USER_TIME hint should not be set at
all unless to say "please do not focus me on map".

The window manager has information from startup notification to fill
in this missing information and decide whether the window should be
mapped.  If the WM needs to map a window and has no USER_TIME hint, it
should try to find a value from startup notification and use that
instead.  If neither value is available, it should give up and focus
the newly mapped window.

Is that what you were asking about, Elijah?
Comment 18 Elijah Newren 2004-02-29 01:51:57 UTC
Rob: Yes, that was basically my question/misunderstanding.  For some
reason I thought I needed to set it in all cases and was trying to
obtain a timestamp in gtk_init from the setting of the _NET_WM_PID
hint in order to do so.  I made sure to have my Metacity patch have
the backup timestamp be overruled by a startup notification timestamp
if both were present.  Anyway, I've removed that and I'm attaching a
fixed patch.
Comment 19 Elijah Newren 2004-02-29 01:52:53 UTC
Created attachment 24917 [details] [review]
Corrected patch
Comment 20 Rob Adams 2004-02-29 02:15:14 UTC
yea, USER_TIME should only ever be set to a real, actual, verified
timestamp obtained from some sort of actual user input.

Also, you should not override USER_TIME with a startup notification
timestamp.  By definition the USER_TIME value would be more recent, so
you should always use that if it's available.

The WM algorithm is as follows:
on map of window w:
   if user_time hint is set
     w.user_time := user_time hint value for w
   else if startup notification stamp is set
     w.user_time := startup notification time stamp w
     w.user_time := CurrentTime

   if (time == CurrentTime or 
      (time >= (currently focused window).user_time)
      focus and raise newly mapped window
      set NEEDS_ATTENTION on w
      stack w just below currently focused window
Comment 21 Elijah Newren 2004-02-29 03:57:47 UTC
Yeah.  Thanks for the patience as I worked to wrap my head around all
the X stuff and the standard.  What you have outlined above is what my
most current gtk patch supports.
Comment 22 Matthias Clasen 2004-03-01 10:17:28 UTC
I had moved this to 2.6 API for the set_focus_on_map addition, but 
thinking about it, we might add the backend in 2.4.x and only move the

addition of set_focus_on_map to 2.6. 2.4.x would always use the 
default value, TRUE.
Comment 23 Owen Taylor 2004-03-01 21:39:20 UTC
The usage of assert() in this patch is incorrect 
a) there is a g_assert(), no need for assert.h
b) you've made it possible to crash the
program by XSendEvent() it an event with a 0 time field,
generally asserting on data not under the control of
the program is wrong.

Other than that, and the missing docs for 
gtk_window_set_focus_on_map(), the patch looks mostly
Comment 24 Elijah Newren 2004-03-01 22:45:01 UTC
Thanks for the reminder about g_assert; I guess old habits die hard.
I had left the assert's there simply for debugging purposes (I had
some mistakes in early versions of the patch that I wanted to catch);
I didn't mean for them to be in the final version.  I'll fix that and
add the relevant docs.
Comment 25 Elijah Newren 2004-03-05 00:07:41 UTC
Created attachment 25184 [details] [review]
Remove asserts sanely
Comment 26 Elijah Newren 2004-03-05 00:12:29 UTC
I removed the assert's.  I tried to determine whether the event
timestamp for XInput events can be depended upon to be valid, but I
couldn't find it googling so I just manually check.

Also, Owen, I'm not sure where you want documentation added.  I have a
stub in gtk-sections and gdk-sections as well as inline comments for
the  .c file.  I added a stub in the windows.sgml and gtkwindow.sgml
files, but let me know if that's not what you meant.
Comment 27 Matthias Clasen 2004-04-13 21:08:34 UTC
Elijah, the doc look fine. Can we get the patch split so that the backend stuff
goes into 2.4 and the new api into 2.6 ?
Comment 28 Soren Sandmann Pedersen 2004-04-13 22:40:13 UTC
Comment on attachment 25184 [details] [review]
Remove asserts sanely

I think the usability benefits from this patch are big enough that we should
try to get it in 2.4.1
Comment 29 Elijah Newren 2004-04-14 18:20:09 UTC
Created attachment 26661 [details] [review]
Patch with API removed

Here's the patch without the API.  This patch still adds the focus_on_map
property, but sets it to TRUE and provides no API for checking or setting its
value.	I thought this would be cleaner since it allows us to add the API later
without making changes to the existing code.  Is this what you wanted, or do
you want me to remove the focus_on_map property as well?
Comment 30 Matthias Clasen 2004-04-14 21:22:23 UTC
Technically, the property is the main api, with the setter and getter just being
C binding sugar. Therefore, the property should be a 2.6 addition as well,
but that seems to be already the case with your patch. 
You remove the PROP_FOCUS_ON_MAP constant, and your patch looks good.

I'd suggest that you attach the api portions of the patch to this bug as a
separate attachment, then we can just move the bug to the 2.6 API milestone after
committing the non-API portions. 

Soeren, will you commit this ?
Comment 31 Elijah Newren 2004-04-14 21:57:06 UTC
Created attachment 26669 [details] [review]
Corrected patch, no PROP_FOCUS_ON_MAP constant

Ooops, yeah I mean to remove that line with the PROP_FOCUS_ON_MAP but
apparently missed it.
Comment 32 Soren Sandmann Pedersen 2004-04-18 14:36:02 UTC
I committed something based on this patch. Changes:

       - made gdk_x11_window_set_user_time() internal
       - removed unused focus_on_map variables

Elijah, I agree with Matthias that it would be a good idea to attach the API
part of the patch. I'm moving it to the 2.6.0 API freeze milestone.

Sun Apr 18 16:15:15 2004  Soeren Sandmann  <>

	Support for _NET_WM_USER_TIME (bug 115650). Patch by Elijah
	* gdk/x11/gdkwindow-x11.[ch]: Add new internal function
	_gdk_x11_set_user_time() to set the _NET_WM_USER_TIME property.

	* gdk/x11/gdkdisplay-x11.h (struct _GdkDisplayX11): Add user_time field

	* gdk/x11/gdkdisplay-x11.c: Add _NET_WM_USER_TIME to list of
	precached atoms.
	* gdk/x11/gdkinput-x11.c, gdk/x11/gdkevents-x11.c: Set the
	property on user interaction.

Comment 33 Miguel Ibarra 2004-04-22 22:13:36 UTC
gdkwindow-x11.c defines _gdk_x11_window_set_user_time
but gdkinput-x11.c uses gdk_x11_window_set_user_time (ie, without the _).

I can't compile GTK+ from cvs HEAD. I'm getting a undefined reference to
Comment 34 Elijah Newren 2004-04-23 04:23:15 UTC
Created attachment 26990 [details] [review]
fix compilation error

It appears that Soeren forgot to
s/gdk_x11_window_set_user_time/_gdk_x11_window_set_user_time/ in the
gdkinput-x11.c file as he had done elsewhere.  Here's the simple patch to fix
that.  Can I commit?  (And yes, I'll try to post the patch with the rest of the
API soon separately)
Comment 35 Elijah Newren 2004-04-29 20:20:53 UTC
Comment on attachment 26990 [details] [review]
fix compilation error

I don't know if Matthias applied this patch and forgot to mark this bug as
committed, or discovered the compilation problem independently an fixed it. 
Anyway, it's fixed now so I'll mark this patch as obsolete.
Comment 36 Elijah Newren 2004-04-29 21:14:52 UTC
Created attachment 27219 [details] [review]
API portion of the patch

Sorry for the delay--I wanted to wait for the other commits (Soeren's
modifications to my patch and Matthias's slight changes) before attaching the
API portion of the patch so that I could avoid future conflicts as much as
possible.  Anyway, here it is.
Comment 37 Matthias Clasen 2004-05-05 23:54:16 UTC
Comment on attachment 27219 [details] [review]
API portion of the patch

Since we've branched for 2.6 now, this is fine to commit.
Comment 38 Elijah Newren 2004-05-06 04:27:03 UTC
I commited, so I'm marking as fixed to close the bug.
Comment 39 Elijah Newren 2004-08-19 21:10:55 UTC
*** Bug 150502 has been marked as a duplicate of this bug. ***
Comment 40 Elijah Newren 2004-08-19 21:17:21 UTC
The patch is incomplete and leaves an important case not working.  If a user is
using an app and:
  1) The app opens another window (e.g. preferences or a confirmation dialog)
  2) The app closes the window (user is done using it or whatever)
  3) The user interacts with other window
  4) The app reopens that extra window (e.g. user wants to modify more
     preferences or whatever)
then the second time the window is reopened it will appear without focus and
behind whatever window currently has focus.  This is because the
_NET_WM_USER_TIME property for that window is that stale value from previous
usage, instead of the timestamp that caused the window to be mapped as it should
be.  So, I'm reopening this bug.  I'll attach a patch momentarily that fixes the
issue.  The patch is against the gtk-2-4 branch; a similar one will be need for
Comment 41 Elijah Newren 2004-08-19 21:29:56 UTC
Created attachment 30764 [details] [review]
Patch to make sure _NET_WM_USER_TIME is updated

Some comments:
  A) We shouldn't always update _NET_WM_USER_TIME when we're about to map
     a window.	There are two cases when we shouldn't:
     1) When the app has already manually set it's value to 0 to request
	no focus
     2) When the app has set _NET_WM_USER_TIME to something more recent than
	the most recent user interaction with the app.	(see bug 150271 for
	a case where this occurs; basically whenever we have a inter-process
	communication this can happen)
     These two things are the reason for the logic in show_window_internal.
  B) The _NET_ACTIVE_WINDOW message was also using an obsolete version of the
     spec, and the newer version is closely related to the _NET_WM_USER_TIME
     stuff, so I updated that too.  However, my data.l[2] is almost certainly
     wrong.  It's supposed to be the id of the currently active window.
  C) This may affect other parts of my patch...the patch from bug 144302 
     modified _gdk_x11_window_set_user_time.  Perhaps the modifications are
     right, but it seems odd to be using a long (which could be 64 bits) to be
     passed as something which is specified to be a pointer to 32 bits.  If it
     is right, then my patch probably shouldn't be using guint32 for the new
     variable I introduct (and I need to fix Metacity...).  Could someone
Comment 42 Elijah Newren 2004-08-19 21:32:31 UTC
Oops, I forgot to mark this as blocking bug 149028, I'll do so now.
Comment 43 Owen Taylor 2004-08-20 20:04:34 UTC
Please reclose this bug and open a new one. Reopening bugs is close
to never right when a fix has gone into CVS. Actually, looks like
two new bugs. A) and B) are unrelated issues.

As for C, the issue is that CARD32 server side items are represented
as longs in the Xlib API, but they still only have 32 bits of 
data in them. Your patch looks OK to me at first glance.
Comment 44 Elijah Newren 2004-08-20 20:25:40 UTC
Okay, sorry for the confusion.  I'll split the patches for (A) and (B).  Thanks
for the clarification on (C).