* Toggle fullscreen with one key
@ 2005-03-17 23:56 Johan Josefsson
2005-03-18 0:57 ` Drew Adams
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Johan Josefsson @ 2005-03-17 23:56 UTC (permalink / raw)
I am currently using two keys (f2 and C-f2) and two functions for
maximizing and restoring the frame in win32:
--- functions
(defun my-frame-maximize () "Maximize Emacs window in win32"
(interactive)
(w32-send-sys-command ?\xf030))
(defun my-frame-restore () "Restore Emacs window in win32"
(interactive)
(w32-send-sys-command ?\xF120))
--- keys
(global-set-key [f2] 'my-frame-maximize) ; Maximize Emacs window
(global-set-key [C-f2] 'my-frame-restore) ; Restore Emacs window
---
It works as intended, but I wonder, is there any simple way to replace
these two keys with a function that use only one key (f2) to toggle
between these two states?
Thanks,
Johan
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Toggle fullscreen with one key
2005-03-17 23:56 Toggle fullscreen with one key Johan Josefsson
@ 2005-03-18 0:57 ` Drew Adams
2005-03-18 1:08 ` Pascal Bourguignon
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2005-03-18 0:57 UTC (permalink / raw)
I am currently using two keys (f2 and C-f2) and two functions for
maximizing and restoring the frame in win32:
Are you using Windows, by chance? If so, just double-click the frame's title
bar to toggle maximizing. - Drew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Toggle fullscreen with one key
2005-03-17 23:56 Toggle fullscreen with one key Johan Josefsson
2005-03-18 0:57 ` Drew Adams
@ 2005-03-18 1:08 ` Pascal Bourguignon
2005-03-18 12:11 ` Mathias Dahl
2005-03-19 0:30 ` rgb
3 siblings, 0 replies; 5+ messages in thread
From: Pascal Bourguignon @ 2005-03-18 1:08 UTC (permalink / raw)
Johan Josefsson <johan.mailinglists@gmail.com> writes:
> I am currently using two keys (f2 and C-f2) and two functions for
> maximizing and restoring the frame in win32:
>
> --- functions
>
> (defun my-frame-maximize () "Maximize Emacs window in win32"
> (interactive)
> (w32-send-sys-command ?\xf030))
>
> (defun my-frame-restore () "Restore Emacs window in win32"
> (interactive)
> (w32-send-sys-command ?\xF120))
>
> --- keys
>
> (global-set-key [f2] 'my-frame-maximize) ; Maximize Emacs window
> (global-set-key [C-f2] 'my-frame-restore) ; Restore Emacs window
>
> ---
>
> It works as intended, but I wonder, is there any simple way to replace
> these two keys with a function that use only one key (f2) to toggle
> between these two states?
;; Of course.
(global-set-key [f2] (function toggle-maximize-frame))
;; You speak about state, so:
(defvar *frame-maximized-states* (make-hash-table)
"Maps frames to their maximized state: When not maximized = nil;
when maximized = ((x y) w h)")
;; assuming each frame has its own state.
;; The following is to clean up the entry in the hash table when the
;; frame is deleted:
(add-hook 'delete-frame-hook
(lambda (frame) (setf (gethash frame *frame-maximized-states*) nil)))
;; Now let's toggle:
(defun toggle-maximize-frame ()
(interactive)
(let* ((frame (selected-frame))
(state (gethash frame *frame-maximized-states*)))
(if state
(progn
(apply (function set-frame-position) frame (first state))
(set-frame-width frame (second state))
(set-frame-height frame (third state))
(setf state nil))
(let ((fp (frame-parameters nil)))
(setf state (list (list (cdr (assoc 'left fp))
(cdr (assoc 'top fp)))
(cdr (assoc 'width fp))
(cdr (assoc 'height fp))))
(set-frame-width frame (max-frame-column-number frame 34))
;; I don't know where these 34 go?
(set-frame-height frame (max-frame-line-number frame))
(set-frame-position frame 0 0)))
(setf (gethash frame *frame-maximized-states*) state)))
;; Using the following auxiliary functions. I have them for X, you'll
;; have to adapt them for Microsoft Windows, or edit toggle-maximize-frame
;; to use your Microsoft Windows specific functions.
(defvar *window-manager-y-offset* (+ 20 11)
"The number of vertical pixels eaten by the window manager
(window title, grow bar).")
(defvar *window-manager-x-offset* 2
"The number of vertical pixels eaten by the window manager.")
(defun font-canonical-to-pixel (canon &optional device)
(let ((pix-width (float (or (device-pixel-width device) 1024)))
(mm-width (float (or (device-mm-width device) 293))))
(/ canon (/ pix-width mm-width) (/ 25.4 72.0))))
(defun get-font-size-in-pixel (font &optional device)
"
RETURN: The font height in pixel.
"
(let ((fs (font-size (font-create-object font))))
(if (numberp fs)
fs
(font-canonical-to-pixel
(font-spatial-to-canonical fs device) device))));;get-font-size-in-pixel
(defun max-frame-line-number (&optional frame)
"
RETURN: The maximum number of line that can be displayed on this frame
inside this screen.
"
(truncate
(/ (- (x-display-pixel-height frame) *window-manager-y-offset*)
(frame-char-height frame))))
(defun max-frame-column-number (&optional frame margin)
"
MARGIN: Number of pixel to substract from the display width.
RETURN: The maximum number of columns that can be displayed on this frame
inside this screen.
"
(setf margin (or margin 0))
(truncate
(/ (- (x-display-pixel-width frame) margin *window-manager-x-offset*)
(frame-char-width frame))))
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Toggle fullscreen with one key
2005-03-17 23:56 Toggle fullscreen with one key Johan Josefsson
2005-03-18 0:57 ` Drew Adams
2005-03-18 1:08 ` Pascal Bourguignon
@ 2005-03-18 12:11 ` Mathias Dahl
2005-03-19 0:30 ` rgb
3 siblings, 0 replies; 5+ messages in thread
From: Mathias Dahl @ 2005-03-18 12:11 UTC (permalink / raw)
Johan Josefsson <johan.mailinglists@gmail.com> writes:
> I am currently using two keys (f2 and C-f2) and two functions for
> maximizing and restoring the frame in win32:
> [...]
> It works as intended, but I wonder, is there any simple way to
> replace these two keys with a function that use only one key (f2) to
> toggle between these two states?
>
This is a bit ugly (one should really check the "real" state of the
frame), but works:
(defvar my-frame-toggle-state nil
"Just a dummy variable too keep track of things")
(defun my-frame-toggle ()
(interactive)
(if my-frame-toggle-state
(my-frame-restore)
(my-frame-maximize))
(setq my-frame-toggle-state (not my-frame-toggle-state)))
(defun my-frame-maximize ()
"Maximize Emacs window in win32"
(interactive)
(w32-send-sys-command ?\xf030))
(defun my-frame-restore ()
"Restore Emacs window in win32"
(interactive)
(w32-send-sys-command ?\xF120))
/Mathias
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Toggle fullscreen with one key
2005-03-17 23:56 Toggle fullscreen with one key Johan Josefsson
` (2 preceding siblings ...)
2005-03-18 12:11 ` Mathias Dahl
@ 2005-03-19 0:30 ` rgb
3 siblings, 0 replies; 5+ messages in thread
From: rgb @ 2005-03-19 0:30 UTC (permalink / raw)
This seems to work pretty well for me.
If you use the restore/maximize buttons or double click the
title bar (etc) my-frame-state could get out of sync but it
re-syncs every time my-frame-maximize or my-frame-restore
are called.
(make-variable-frame-local 'my-frame-state)
>
> (defun my-frame-maximize () "Maximize Emacs window in win32"
> (interactive)
(modify-frame-parameters nil '((my-frame-state . t)))
> (w32-send-sys-command ?\xf030))
>
> (defun my-frame-restore () "Restore Emacs window in win32"
> (interactive)
(modify-frame-parameters nil '((my-frame-state . nil)))
> (w32-send-sys-command ?\xF120))
>
(defun my-frame-toggle ()
"Maximize/Restore Emacs frame based on `my-frame-state'"
(interactive)
(if my-frame-state
(my-frame-restore)
(my-frame-maximize)))
> --- keys
>
(global-set-key [f2] 'my-frame-toggle)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-03-19 0:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-17 23:56 Toggle fullscreen with one key Johan Josefsson
2005-03-18 0:57 ` Drew Adams
2005-03-18 1:08 ` Pascal Bourguignon
2005-03-18 12:11 ` Mathias Dahl
2005-03-19 0:30 ` rgb
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.