From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Toggle fullscreen with one key Date: 18 Mar 2005 02:08:02 +0100 Organization: [posted via Easynet Spain] Message-ID: <874qf9g3rh.fsf@thalassa.informatimago.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1111108114 6619 80.91.229.2 (18 Mar 2005 01:08:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 18 Mar 2005 01:08:34 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 18 02:08:33 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DC5yS-0004F2-OW for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Mar 2005 02:08:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DC6Eq-0000z3-Mw for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Mar 2005 20:25:20 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!colt.net!easynet-quince!easynet.net!easynet-post2!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-Lines: 126 Original-NNTP-Posting-Host: 62.93.174.79 Original-X-Trace: DXC=HdRlmUle1^NnlQj7RbBd4DjF1d]Q Original-Xref: shelby.stanford.edu gnu.emacs.help:129358 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: news.gmane.org gmane.emacs.help:24913 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24913 Johan Josefsson 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