2015 年更新:Emacs 24.4 包括对使用toggle-frame-fullscreen
. 您可以不加修改地使用适用于 Windows 的 GNU 构建(或者,可能是任何其他构建)。
问题是 GUI 以整个字符来调整窗口大小。这只是 Windows 上的一个问题,因为您没有frame-parameter
转换为原生全屏的 a,因此全屏模式必须通过调整大小和定位来完成。
您需要EmacsW32修补版本。
从此下载页面获取最新的安装程序(当前为 Emacs-24-BzrP110217-EmacsW32-1.58.exe) 。
这与诸如emacs-fullscreen-w32之类的东西(使用 Windows API 删除标题栏)结合使用,将为您提供真正的全屏显示。
相信我,没有其他方法可以消除 Windows 上的差距。
就个人而言,我不喜欢在我的.emacs
repo 中使用某人的 EXE,所以我使用以下 C# 程序(我从这个 bitbucket 项目中获得):
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace toggleTitle
{
class Program
{
// Constants from WinUser.h
const int GWL_STYLE = -16;
const int GWL_EXSTYLE = -20;
const int SW_MAXIMIZE = 3;
const uint WS_CAPTION = 0x00C00000;
const uint WS_BORDER = 0x00800000;
const uint WS_SIZEBOX = 0x000040000;
// Imports from user32.dll
[DllImport("User32", CharSet = CharSet.Auto)]
private static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);
[DllImport("User32", CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int Index);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
// -- main functions
static int GetWindowStyle(int hwnd) {
return GetWindowLong(new IntPtr(hwnd), GWL_STYLE);
}
static void ToggleWindowCaption(int hwnd) {
IntPtr intPtrHWND = new IntPtr(hwnd);
int currentStyle = GetWindowStyle(hwnd);
int newStyle = currentStyle ^ (int) WS_CAPTION;
newStyle = newStyle ^ (int)WS_BORDER;
newStyle = newStyle ^ (int)WS_SIZEBOX;
SetWindowLong(intPtrHWND, GWL_STYLE, newStyle);
WinApi.SetWinFullScreen(intPtrHWND);
//ShowWindow(hwnd, SW_MAXIMIZE);
}
static List<Process> FindWindows(Regex regexpToMatch) {
List<Process> results = new List<Process>();
foreach (Process win in Process.GetProcesses()) {
if (regexpToMatch.IsMatch(win.MainWindowTitle)) {
results.Add(win);
}
}
return results;
}
static void Main(string[] args) {
System.Console.WriteLine("== toggle windows ==");
if (args.Length < 1) {
Console.WriteLine("Usage: togglecaption <hwnd>");
return;
}
int windowHwnd = Int32.Parse(args[0]);
foreach (Process proc in Process.GetProcesses()) {
if (proc.MainWindowHandle == new IntPtr(windowHwnd)) {
System.Console.WriteLine(proc.MainWindowTitle);
Console.WriteLine("Toggled WS_CAPTION on: " + proc.MainWindowTitle);
ToggleWindowCaption(windowHwnd);
return;
}
}
Console.WriteLine("hwnd not found. Exiting.");
}
}
public class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0×0040
private const int SWP_NOSIZE = 1;
private const int SWP_NOMOVE = 2;
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN);}
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN);}
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE);
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX + 7, ScreenY + 7, SWP_SHOWWINDOW | SWP_NOMOVE);
}
}
}
这构建了一个简单的
csc /out:w32toggletitle.exe *.cs
如果 .NET Framework 目录在您的路径中。
我将生成的 EXE 放在我的路径中,并使用以下 elisp 代码来调用它(也改编自各种来源):
(setq gpc/frame-box-before-fullscreen nil)
(defun toggle-titlebar ()
"Toggles the titlebar on the current frame (Windows only)."
(interactive)
(call-process (dot-emacs "winpatch/bin/w32toggletitle.exe")
nil nil nil
(frame-parameter (selected-frame) 'window-id)))
(defun toggle-fullscreen ()
"Toggle fullscreen."
(interactive)
(if (frame-parameter nil 'fullscreen)
(fullscreen-off)
(fullscreen-on)))
(defun fullscreen-on ()
"Makes emacs frame occupy the full screen, even on Windows."
(interactive)
(setq gpc/frame-box-before-fullscreen
`((top . ,(frame-parameter nil 'top))
(left . ,(frame-parameter nil 'left))
(width . ,(frame-parameter nil 'width))
(height . ,(frame-parameter nil 'height))))
(when (eq window-system 'w32)
(unless (frame-parameter nil 'fullscreen)
(toggle-titlebar))
(w32-send-sys-command 61488))
(set-frame-parameter nil 'fullscreen 'fullboth))
(defun fullscreen-off ()
"Restore frame from fullscreen mode (Windows only... I think)"
(interactive)
(when (eq window-system 'w32)
(w32-send-sys-command 61728)
;; HACK to test if titlebar is on or off
(if (frame-parameter nil 'fullscreen)
(toggle-titlebar)))
(set-frame-parameter nil 'fullscreen nil)
(modify-frame-parameters nil gpc/frame-box-before-fullscreen))
然后我用
(global-set-key (kbd "<f11>") 'toggle-fullscreen)
当处于 GUI 模式时,F11 可以按预期工作,包括保存/恢复窗口位置。
我个人在这方面花费了太多时间,所以我希望这可以挽救其他人的死胡同。
最重要的是,如果您想在 Windows 上实现真正的 emacs 全屏,请使用 Lennart 的补丁。GNU 构建和 Cygwin w32 构建都将窗口大小强制为整个字符。