Toggle fullscreen on super/ctrl+return, only macOS for now

This fixes or at least is the first step towards #171:

- it adds `cmd/super + return` as the default keybinding to toggle
  fullscreen for currently focused window.
- it adds a keybinding handler to the embedded apprt and then changes
  the macOS app to handle the keybinding by toggling currently focused
  window.
This commit is contained in:
Thorsten Ball
2023-07-02 19:59:41 +02:00
parent ce77002198
commit 8e464db049
8 changed files with 56 additions and 1 deletions

View File

@@ -1135,6 +1135,12 @@ pub fn keyCallback(
} else log.warn("runtime doesn't implement gotoSplit", .{});
},
.toggle_fullscreen => {
if (@hasDecl(apprt.Surface, "toggleFullscreen")) {
self.rt_surface.toggleFullscreen();
} else log.warn("runtime doesn't implement toggleFullscreen", .{});
},
.close_surface => self.close(),
.close_window => {

View File

@@ -64,6 +64,9 @@ pub const App = struct {
/// Goto tab
goto_tab: ?*const fn (SurfaceUD, usize) callconv(.C) void = null,
/// Toggle fullscreen for current window.
toggle_fullscreen: ?*const fn (SurfaceUD) callconv(.C) void = null,
};
core_app: *CoreApp,
@@ -371,6 +374,15 @@ pub const Surface = struct {
func(self.opts.userdata, n);
}
pub fn toggleFullscreen(self: *Surface) void {
const func = self.app.opts.toggle_fullscreen orelse {
log.info("runtime embedder does not toggle_fullscreen", .{});
return;
};
func(self.opts.userdata);
}
/// The cursor position from the host directly is in screen coordinates but
/// all our interface works in pixels.
fn cursorPosToPixels(self: *const Surface, pos: apprt.CursorPos) !apprt.CursorPos {

View File

@@ -441,6 +441,13 @@ pub const Config = struct {
}
}
// Toggle fullscreen
try result.keybind.set.put(
alloc,
.{ .key = .enter, .mods = ctrlOrSuper(.{}) },
.{ .toggle_fullscreen = {} },
);
// Mac-specific keyboard bindings.
if (comptime builtin.target.isDarwin()) {
try result.keybind.set.put(

View File

@@ -207,6 +207,9 @@ pub const Action = union(enum) {
/// Close the window, regardless of how many tabs or splits there may be.
close_window: void,
/// Toggle fullscreen mode of window.
toggle_fullscreen: void,
/// Quit ghostty
quit: void,