4

Is there a way to add a hook for when emacs goes full screen? I'd like to set slightly different transparency for the frame when in fullscreen but there seems to be no easy way for that.

What I would want is for emacs to detect it is now in fullscreen and subsequently change its transparency.

4

The only hook I know of that might help is window-size-change-functions.

Code such as this, for example (replace the message call by whatever you want done:

(defun foo (frame)
  (let ((fullscreen  (frame-parameter frame 'fullscreen)))
    (when (memq fullscreen '(fullscreen fullboth))
      (message "Do what you want here."))))

(add-hook 'window-size-change-functions 'foo)

This hook runs each time there is a change in any window size the hook functions are invoked. C-h v says:

Functions called during redisplay, if window sizes have changed. The value should be a list of functions that take one argument. During the first part of redisplay, for each frame, if any of its windows have changed size since the last redisplay, or have been split or deleted, all the functions in the list are called, with the frame as argument. If redisplay decides to resize the minibuffer window, it calls these functions on behalf of that as well.

You can instead advise a function, such as toggle-frame-fullscreen (bound to <f11>), that makes the frame fullscreen.


Emacs hooks and such advice will not, however, be called when you use window-manager artifacts, such as a maximize/restore icon/button.

It's possible to invoke Elisp code when some window-manager events, such as clicking the iconify/minimize icon/button. You do that using keymap special-event-map.

For example, to do something different from iconifying when you click the iconify/minimize button, you can do this:

(define-key special-event-map [iconify-frame] 'my-frame-action)

I take advantage of that, optionally, in my library thumb-frm.el, for example -- Fisheye With Thumbs.

(Be aware of this fact/feature, which is true of any binding on keymap special-event-map: The event interrupts any key sequence in progress, to invoke its command, and then the key sequence as a whole is processed, ignoring the special event.)

However, as far as I can tell, the maximize/restore icon/button is not associated by Emacs with a special event. (Iconify/minimize is, but maximize is not.) So I don't see a way to make the window-manager maximize/restore button invoke Elisp code. Maybe someone else has some suggestion about this.

5
  • I have tried using the code for window-size-change-functions you provided and it first it looked like it worked just the way I intended it to work but then it occurred to me that switching buffer triggered the function (foo here) to work as if it was the fullscreen and after some further tests it's the ivy buffer that does that -- eg M-x also triggers the function to execute as if the frame were in fullscreen – ggegoge Apr 29 at 13:31
  • Sorry, I don't understand your comment. If it's a new question (I'm guessing it is), please submit that separately. If it's a clarification of this question, please edit the question. – Drew Apr 29 at 14:22
  • My initial intention was to have a "fullscreen hook" that would simply change window's transparency each time I resize it depending on whether it is fullscreened or not. I have tried using your code with the window-size-change-functions and it does detect entering fullscreen but also each time I use commands that use ivy completion it seems like emacs also calls the function I've added as if the window was fullscreen. So: I resize the frame -- transparency changes as I wanted. But also: I call eg M-x -- it changes as well. I hope that's more clear (I think it is still the same question) – ggegoge Apr 29 at 17:39
  • See the definition of that hook - yes, it's run for every window size change. Your hook function for it should choose to do nothing for the cases you're not interested in. – Drew Apr 29 at 17:54
  • @ggegoge Bear in mind that what Emacs calls a window is not the same thing that an operating system/window manager calls a "window"; that's called a frame in Emacs. An Emacs window is what would be called a "pane" elsewhere. Hope that's clarifying not confusing. See (info "(emacs) Windows") and (info "(emacs) Frames"). – Phil Hudson May 4 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.