mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk-ng: toggle fullscreen and maximize
This commit is contained in:
@ -509,9 +509,10 @@ pub const Application = extern struct {
|
||||
|
||||
.show_gtk_inspector => Action.showGtkInspector(),
|
||||
|
||||
.toggle_maximize => Action.toggleMaximize(target),
|
||||
.toggle_fullscreen => Action.toggleFullscreen(target),
|
||||
|
||||
// Unimplemented but todo on gtk-ng branch
|
||||
.toggle_maximize,
|
||||
.toggle_fullscreen,
|
||||
.new_tab,
|
||||
.goto_tab,
|
||||
.move_tab,
|
||||
@ -1237,6 +1238,20 @@ const Action = struct {
|
||||
pub fn showGtkInspector() void {
|
||||
gtk.Window.setInteractiveDebugging(@intFromBool(true));
|
||||
}
|
||||
|
||||
pub fn toggleFullscreen(target: apprt.Target) void {
|
||||
switch (target) {
|
||||
.app => {},
|
||||
.surface => |v| v.rt_surface.surface.toggleFullscreen(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggleMaximize(target: apprt.Target) void {
|
||||
switch (target) {
|
||||
.app => {},
|
||||
.surface => |v| v.rt_surface.surface.toggleMaximize(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// This sets various GTK-related environment variables as necessary
|
||||
|
@ -209,6 +209,26 @@ pub const Surface = extern struct {
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
pub const zoom = struct {
|
||||
pub const name = "zoom";
|
||||
const impl = gobject.ext.defineProperty(
|
||||
name,
|
||||
Self,
|
||||
bool,
|
||||
.{
|
||||
.nick = "Zoom",
|
||||
.blurb = "Whether the surface should be zoomed.",
|
||||
.default = false,
|
||||
.accessor = gobject.ext.privateFieldAccessor(
|
||||
Self,
|
||||
Private,
|
||||
&Private.offset,
|
||||
"zoom",
|
||||
),
|
||||
},
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
pub const signals = struct {
|
||||
@ -271,6 +291,32 @@ pub const Surface = extern struct {
|
||||
void,
|
||||
);
|
||||
};
|
||||
|
||||
/// Emitted when this surface requests its container to toggle its
|
||||
/// fullscreen state.
|
||||
pub const @"toggle-fullscreen" = struct {
|
||||
pub const name = "toggle-fullscreen";
|
||||
pub const connect = impl.connect;
|
||||
const impl = gobject.ext.defineSignal(
|
||||
name,
|
||||
Self,
|
||||
&.{},
|
||||
void,
|
||||
);
|
||||
};
|
||||
|
||||
/// Emitted when this surface requests its container to toggle its
|
||||
/// maximized state.
|
||||
pub const @"toggle-maximize" = struct {
|
||||
pub const name = "toggle-maximize";
|
||||
pub const connect = impl.connect;
|
||||
const impl = gobject.ext.defineSignal(
|
||||
name,
|
||||
Self,
|
||||
&.{},
|
||||
void,
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
const Private = struct {
|
||||
@ -310,6 +356,10 @@ pub const Surface = extern struct {
|
||||
/// focus events.
|
||||
focused: bool = true,
|
||||
|
||||
/// Whether this surface is "zoomed" or not. A zoomed surface
|
||||
/// shows up taking the full bounds of a split view.
|
||||
zoom: bool = false,
|
||||
|
||||
/// The GLAarea that renders the actual surface. This is a binding
|
||||
/// to the template so it doesn't have to be unrefed manually.
|
||||
gl_area: *gtk.GLArea,
|
||||
@ -430,6 +480,24 @@ pub const Surface = extern struct {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn toggleFullscreen(self: *Self) void {
|
||||
signals.@"toggle-fullscreen".impl.emit(
|
||||
self,
|
||||
null,
|
||||
.{},
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn toggleMaximize(self: *Self) void {
|
||||
signals.@"toggle-maximize".impl.emit(
|
||||
self,
|
||||
null,
|
||||
.{},
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Set the current progress report state.
|
||||
pub fn setProgressReport(
|
||||
self: *Self,
|
||||
@ -2076,6 +2144,7 @@ pub const Surface = extern struct {
|
||||
properties.@"mouse-hover-url".impl,
|
||||
properties.pwd.impl,
|
||||
properties.title.impl,
|
||||
properties.zoom.impl,
|
||||
});
|
||||
|
||||
// Signals
|
||||
@ -2083,6 +2152,8 @@ pub const Surface = extern struct {
|
||||
signals.bell.impl.register(.{});
|
||||
signals.@"clipboard-read".impl.register(.{});
|
||||
signals.@"clipboard-write".impl.register(.{});
|
||||
signals.@"toggle-fullscreen".impl.register(.{});
|
||||
signals.@"toggle-maximize".impl.register(.{});
|
||||
|
||||
// Virtual methods
|
||||
gobject.Object.virtual_methods.dispose.implement(class, &dispose);
|
||||
|
@ -142,6 +142,34 @@ pub const Window = extern struct {
|
||||
self.as(gtk.Window).close();
|
||||
}
|
||||
|
||||
fn surfaceToggleFullscreen(
|
||||
surface: *Surface,
|
||||
self: *Self,
|
||||
) callconv(.c) void {
|
||||
_ = surface;
|
||||
if (self.as(gtk.Window).isMaximized() != 0) {
|
||||
self.as(gtk.Window).unmaximize();
|
||||
} else {
|
||||
self.as(gtk.Window).maximize();
|
||||
}
|
||||
|
||||
// We react to the changes in the propFullscreen callback
|
||||
}
|
||||
|
||||
fn surfaceToggleMaximize(
|
||||
surface: *Surface,
|
||||
self: *Self,
|
||||
) callconv(.c) void {
|
||||
_ = surface;
|
||||
if (self.as(gtk.Window).isMaximized() != 0) {
|
||||
self.as(gtk.Window).unmaximize();
|
||||
} else {
|
||||
self.as(gtk.Window).maximize();
|
||||
}
|
||||
|
||||
// We react to the changes in the propMaximized callback
|
||||
}
|
||||
|
||||
fn actionAbout(
|
||||
_: *gio.SimpleAction,
|
||||
_: ?*glib.Variant,
|
||||
@ -219,6 +247,8 @@ pub const Window = extern struct {
|
||||
|
||||
// Template Callbacks
|
||||
class.bindTemplateCallback("surface_close_request", &surfaceCloseRequest);
|
||||
class.bindTemplateCallback("surface_toggle_fullscreen", &surfaceToggleFullscreen);
|
||||
class.bindTemplateCallback("surface_toggle_maximize", &surfaceToggleMaximize);
|
||||
|
||||
// Virtual methods
|
||||
gobject.Object.virtual_methods.dispose.implement(class, &dispose);
|
||||
|
@ -40,6 +40,8 @@ template $GhosttyWindow: Adw.ApplicationWindow {
|
||||
|
||||
$GhosttySurface surface {
|
||||
close-request => $surface_close_request();
|
||||
toggle-fullscreen => $surface_toggle_fullscreen();
|
||||
toggle-maximize => $surface_toggle_maximize();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user