Reputation:
I've also come across this discussion: http://www.reddit.com/r/emacs/comments/15gd16/osx_a_window_sizing_problem/ but I'm on Windows now (GUI Emacs doesn't have this behavior when running in Gnome or KDE).
The problem is that the Emacs' window doesn't fill the entire screen. I tried different fonts, but couldn't find a good combination (actually, none of those I tried filled the whole screen). So, I was thinking... maybe, did anyone come up with a solution to this? It really looks sloppy when some random bit of another program shows up below the minibuffer.
Upvotes: 2
Views: 1958
Reputation: 43188
UPDATE 2015: Emacs 24.4 includes true fullscreen support for Windows using toggle-frame-fullscreen
. You can use the GNU build for Windows with no modifications (or, presumably, any other build).
The issue is that the GUI sizes the window in whole characters. This is only an issue on Windows because you don't have a frame-parameter
that translates to native fullscreen, and thus full-screen mode has to be accomplished through sizing and positioning.
You need the EmacsW32 patched build.
Get the latest installer (currently Emacs-24-BzrP110217-EmacsW32-1.58.exe) from this download page.
This, used in conjunction with something like emacs-fullscreen-w32 (to remove the titlebar using the Windows API), will give you true fullscreen.
Trust me, there is no other way to get rid of the gap on Windows.
Personally, I didn't like slinging around someone's EXE in my .emacs
repo, so I use the following C# program (which I got from this bitbucket project):
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);
}
}
}
This builds with a simple
csc /out:w32toggletitle.exe *.cs
if a .NET Framework directory is in your path.
I put the resulting EXE in my path, and I use the following elisp code to invoke it (also adapted from various sources):
(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))
I then use
(global-set-key (kbd "<f11>") 'toggle-fullscreen)
when in GUI mode so that F11 works as you'd expect, including save/restore of the window position.
I have personally spent way too much time on this, so I hope this saves someone else the dead ends.
Bottom line, if you want true emacs fullscreen on Windows, use Lennart's patches. The GNU build and the Cygwin w32 build all force the window size to whole characters.
Upvotes: 4
Reputation: 1
This solution is simpler than harpo's and does not resolve the issue of Emacs resizing based on characters instead of resolution. The advantage of my solution however is that you do not need to recompile Emacs, and that it works on recent editions of Emacs (I'm using 24.3.)
I stumbled upon this post while searching for a solution for it myself, and seeing that the Emacs releases harpo linked to is out of date, I figured I would try to make a solution of my own.
After some research, I found I could make a seemingly robust solution using a single AutoHotKey script.
I posted the solution at the Emacs wiki, but I repost it here in case others stumble across this post while searching for the same keywords in Google. Here is my post from the wiki:
I dabbled with a AutoHotKey script for getting this to work properly, and this is my solution:
SetTitleMatchMode 1 ; matches only the start of the window name WinMaximize, emacs@ ; emacs@ refers to the title of the window WinSet, Style, -0x40000, emacs@ ; removes the thick frame WinSet, Style, -0x800000, emacs@ ; removes the rest of the border
Put this into a text file, change the extension to .ahk and right click and select compile in order to compile it (you need AutoHotKey installed). The 3rd and 4th line disables thick borders (WS_THICKFRAME) and the border (WS_BORDER) respectively. If done in this order, I get no gaps where the background shines through. In order to do this automatically every time you start emacs, add this to your .emacs
(shell-command "<name of compiled ahk script>")
Where the <> and contents is replaced by the filename (with extension) of the complied ahk script. Make sure the complied script is in your path (search for changing environmental variables in a search engine if you don’t know how to do this). I’m using the GNU distribution of Emacs 24.3, using 2560x1600 resolution with the Terminus font (size 9). I’m running this on Windows 8.1. Note that I have also added
(tool-bar-mode -1)
to my .emacs (which is when the problems started occuring.)
I’ve experimented with other fonts and different font sizes. This seems robust.
Upvotes: 0