Subject: bug#49997: 27.2; idle-time reset when switching desktop-page

From: Eli Zaretskii <[email-masked]>
Date: Sun, 15 Aug 2021 19:46:52 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Sun, 15 Aug 2021 18:17:06 +0200
> 
> static void
> x_focus_changed (int type, int state, struct x_display_info *dpyinfo, struct frame *frame, struct input_event *bufp)
> {
>   if (type == FocusIn)
>     {
>       if (dpyinfo->x_focus_event_frame != frame)
>         {
>           x_new_focus_frame (dpyinfo, frame);
>           dpyinfo->x_focus_event_frame = frame;
>           bufp->kind = FOCUS_IN_EVENT;
>           XSETFRAME (bufp->frame_or_window, frame);
>         }
> 
>       frame->output_data.x->focus_state |= state;
> [...]
>   else if (type == FocusOut)
>     {
>       frame->output_data.x->focus_state &= ~state;
> 
> So we lose focus and then get it back, and that makes Emacs unidle.

If we get focus in/out events when the user changes the page, then
it's the correct behavior.

> Which is arguably correct behaviour, but I can see the case for changing
> that.  I mean, the user hasn't done anything inside Emacs.

The user switched off the Emacs frame, which is something, not
nothing.

Why exactly does the stop of idleness present a problem in this case?
And if it does present a problem, cannot the OP use
after-focus-change-function to restart the idleness?