mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk: add toggle_background_opacity option
This commit is contained in:
@ -570,6 +570,7 @@ typedef enum {
|
||||
GHOSTTY_ACTION_TOGGLE_FULLSCREEN,
|
||||
GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW,
|
||||
GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS,
|
||||
GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY,
|
||||
GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL,
|
||||
GHOSTTY_ACTION_TOGGLE_VISIBILITY,
|
||||
GHOSTTY_ACTION_MOVE_TAB,
|
||||
|
@ -4257,6 +4257,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
{},
|
||||
),
|
||||
|
||||
.toggle_background_opacity => return try self.rt_app.performAction(
|
||||
.{ .surface = self },
|
||||
.toggle_background_opacity,
|
||||
{},
|
||||
),
|
||||
|
||||
.toggle_tab_overview => return try self.rt_app.performAction(
|
||||
.{ .surface = self },
|
||||
.toggle_tab_overview,
|
||||
|
@ -104,6 +104,9 @@ pub const Action = union(Key) {
|
||||
/// Toggle whether window directions are shown.
|
||||
toggle_window_decorations,
|
||||
|
||||
/// Toggle the background opacity of the target terminal.
|
||||
toggle_background_opacity,
|
||||
|
||||
/// Toggle the quick terminal in or out.
|
||||
toggle_quick_terminal,
|
||||
|
||||
@ -253,6 +256,7 @@ pub const Action = union(Key) {
|
||||
toggle_fullscreen,
|
||||
toggle_tab_overview,
|
||||
toggle_window_decorations,
|
||||
toggle_background_opacity,
|
||||
toggle_quick_terminal,
|
||||
toggle_visibility,
|
||||
move_tab,
|
||||
|
@ -222,6 +222,7 @@ pub const App = struct {
|
||||
.close_tab,
|
||||
.toggle_tab_overview,
|
||||
.toggle_window_decorations,
|
||||
.toggle_background_opacity,
|
||||
.toggle_quick_terminal,
|
||||
.toggle_visibility,
|
||||
.goto_tab,
|
||||
|
@ -499,6 +499,7 @@ pub fn performAction(
|
||||
.toggle_tab_overview => self.toggleTabOverview(target),
|
||||
.toggle_split_zoom => self.toggleSplitZoom(target),
|
||||
.toggle_window_decorations => self.toggleWindowDecorations(target),
|
||||
.toggle_background_opacity => self.toggleBackgroundOpacity(target),
|
||||
.quit_timer => self.quitTimer(value),
|
||||
.prompt_title => try self.promptTitle(target),
|
||||
.toggle_quick_terminal => return try self.toggleQuickTerminal(),
|
||||
@ -796,6 +797,25 @@ fn toggleQuickTerminal(self: *App) !bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn toggleBackgroundOpacity(
|
||||
_: *App,
|
||||
target: apprt.Target,
|
||||
) void {
|
||||
switch (target) {
|
||||
.app => {},
|
||||
.surface => |v| {
|
||||
const window = v.rt_surface.container.window() orelse {
|
||||
log.info(
|
||||
"toggleBackgroundOpacity invalid for container={s}",
|
||||
.{@tagName(v.rt_surface.container)},
|
||||
);
|
||||
return;
|
||||
};
|
||||
window.toggleBackgroundOpacity();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn quitTimer(self: *App, mode: apprt.action.QuitTimer) void {
|
||||
switch (mode) {
|
||||
.start => self.startQuitTimer(),
|
||||
|
@ -661,6 +661,17 @@ pub fn toggleWindowDecorations(self: *Window) void {
|
||||
};
|
||||
}
|
||||
|
||||
/// Toggle the background opacity for this window.
|
||||
pub fn toggleBackgroundOpacity(self: *Window) void {
|
||||
if (self.app.config.@"background-opacity" >= 1) return;
|
||||
|
||||
if (c.gtk_widget_has_css_class(@ptrCast(self.window), "background") == 1) {
|
||||
c.gtk_widget_remove_css_class(@ptrCast(self.window), "background");
|
||||
} else {
|
||||
c.gtk_widget_add_css_class(@ptrCast(self.window), "background");
|
||||
}
|
||||
}
|
||||
|
||||
/// Grabs focus on the currently selected tab.
|
||||
pub fn focusCurrentTab(self: *Window) void {
|
||||
const tab = self.notebook.currentTab() orelse return;
|
||||
|
@ -431,6 +431,9 @@ pub const Action = union(enum) {
|
||||
/// Toggle window decorations on and off. This only works on Linux.
|
||||
toggle_window_decorations: void,
|
||||
|
||||
/// Toggle background opacity of window.
|
||||
toggle_background_opacity: void,
|
||||
|
||||
/// Toggle secure input mode on or off. This is used to prevent apps
|
||||
/// that monitor input from seeing what you type. This is useful for
|
||||
/// entering passwords or other sensitive information.
|
||||
@ -776,6 +779,7 @@ pub const Action = union(enum) {
|
||||
.toggle_maximize,
|
||||
.toggle_fullscreen,
|
||||
.toggle_window_decorations,
|
||||
.toggle_background_opacity,
|
||||
.toggle_secure_input,
|
||||
.reset_window_size,
|
||||
.crash,
|
||||
|
Reference in New Issue
Block a user