5

I have this notification system in emacs that opens a new buffer with a reminder and relevant info at specified times. However, if I am using my browser I can't see it.

Therefore I am wondering whether it is possible to open a new emacs frame that steals the focus from other apps?

Drew
  • 75,699
  • 9
  • 109
  • 225
The Unfun Cat
  • 2,393
  • 16
  • 32
  • Is it possible to steal the focus from other apps in general, without creating a new frame? If there was a variable for the current frame, (select-frame-set-input-focus current-frame-variable) could be used. This would be super neat for this package I'm thinking of creating. – The Unfun Cat Feb 28 '15 at 08:16
  • 1
    There is: `(select-frame-set-input-focus (selected-frame))` I love you emacs!!!! – The Unfun Cat Feb 28 '15 at 08:20

2 Answers2

1

This should work:

(run-with-timer
 3 nil
 (lambda ()
   (select-frame-set-input-focus (new-frame)))) 
The Unfun Cat
  • 2,393
  • 16
  • 32
abo-abo
  • 13,943
  • 1
  • 29
  • 43
1

What @abo-abo says is almost enough to do what you want (since you explicitly ask not only that the frame be shown on top but also that it be focused).

What it leaves out is that raising a frame does not necessarily focus it (select it for input focus). The behavior can depend on your window manager.

On MS Windows, you can set or bind variable w32-grab-focus-on-raise to cause raising to always also focus.

And you can add a call to select-frame-set-input-focus to your code. That explicitly focuses the frame.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • The last line did the trick. UV. – The Unfun Cat Feb 28 '15 at 08:10
  • I accepted abo-abos answer since he was first, but your help and comments were much appreciated. Is this yours: http://www.emacswiki.org/emacs/frame-fns.el ? I leafed through it and it improved my understanding of how frames work greatly. Thanks. – The Unfun Cat Feb 28 '15 at 08:22
  • You did the right thing - my post was meant to complement @abo-abo's. And yes, hope it helps. – Drew Feb 28 '15 at 16:13