mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk: window actions should use currently active surface
This commit is contained in:
@ -434,19 +434,6 @@ fn initMenu(self: *App) void {
|
||||
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
|
||||
c.g_menu_append(section, "New Window", "win.new_window");
|
||||
c.g_menu_append(section, "New Tab", "win.new_tab");
|
||||
}
|
||||
|
||||
{
|
||||
const section = c.g_menu_new();
|
||||
defer c.g_object_unref(section);
|
||||
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
|
||||
c.g_menu_append(section, "Reload Configuration", "app.reload_config");
|
||||
}
|
||||
|
||||
{
|
||||
const section = c.g_menu_new();
|
||||
defer c.g_object_unref(section);
|
||||
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
|
||||
c.g_menu_append(section, "Close Window", "win.close");
|
||||
}
|
||||
|
||||
@ -454,6 +441,7 @@ fn initMenu(self: *App) void {
|
||||
const section = c.g_menu_new();
|
||||
defer c.g_object_unref(section);
|
||||
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
|
||||
c.g_menu_append(section, "Reload Configuration", "app.reload_config");
|
||||
c.g_menu_append(section, "About Ghostty", "win.about");
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ fn gtkActionClose(
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const self: *Window = @ptrCast(@alignCast(ud orelse return));
|
||||
const surface = self.app.core_app.focusedSurface() orelse return;
|
||||
const surface = self.actionSurface() orelse return;
|
||||
surface.performBindingAction(.{ .close_surface = {} }) catch |err| {
|
||||
log.warn("error performing binding action error={}", .{err});
|
||||
return;
|
||||
@ -530,7 +530,7 @@ fn gtkActionNewWindow(
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const self: *Window = @ptrCast(@alignCast(ud orelse return));
|
||||
const surface = self.app.core_app.focusedSurface() orelse return;
|
||||
const surface = self.actionSurface() orelse return;
|
||||
surface.performBindingAction(.{ .new_window = {} }) catch |err| {
|
||||
log.warn("error performing binding action error={}", .{err});
|
||||
return;
|
||||
@ -543,13 +543,23 @@ fn gtkActionNewTab(
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const self: *Window = @ptrCast(@alignCast(ud orelse return));
|
||||
const surface = self.app.core_app.focusedSurface() orelse return;
|
||||
const surface = self.actionSurface() orelse return;
|
||||
surface.performBindingAction(.{ .new_tab = {} }) catch |err| {
|
||||
log.warn("error performing binding action error={}", .{err});
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the surface to use for an action.
|
||||
fn actionSurface(self: *Window) ?*CoreSurface {
|
||||
const page_idx = c.gtk_notebook_get_current_page(self.notebook);
|
||||
const page = c.gtk_notebook_get_nth_page(self.notebook, page_idx);
|
||||
const surface: *Surface = @ptrCast(@alignCast(
|
||||
c.g_object_get_data(@ptrCast(page), GL_AREA_SURFACE) orelse return null,
|
||||
));
|
||||
return &surface.core_surface;
|
||||
}
|
||||
|
||||
fn userdataSelf(ud: *anyopaque) *Window {
|
||||
return @ptrCast(@alignCast(ud));
|
||||
}
|
||||
|
Reference in New Issue
Block a user