mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Cleanup previous PR
This commit is contained in:
@@ -122,6 +122,10 @@ Detailed list of changes
|
|||||||
- New support for creating and switching to :doc:`sessions` easily, allowing
|
- New support for creating and switching to :doc:`sessions` easily, allowing
|
||||||
users to define and use sessions/projects efficiently
|
users to define and use sessions/projects efficiently
|
||||||
|
|
||||||
|
- macOS: Allow the window title bar to be semi-transparent when
|
||||||
|
:opt:`background_opacity` is less than one and :opt:`macos_titlebar_color` is
|
||||||
|
set to ``background`` (:pull:`8906`)
|
||||||
|
|
||||||
- A new :opt:`cursor_trail_color` setting to independently control the color of
|
- A new :opt:`cursor_trail_color` setting to independently control the color of
|
||||||
cursor trails (:pull:`8830`)
|
cursor trails (:pull:`8830`)
|
||||||
|
|
||||||
|
|||||||
@@ -3168,34 +3168,60 @@ GLFWAPI GLFWcocoarenderframefun glfwCocoaSetWindowResizeCallback(GLFWwindow *w,
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTitlebarBackgroundColor(NSWindow *window, NSColor *backgroundColor) {
|
@implementation NSView (FindByIdentifier)
|
||||||
if (!window) return;
|
|
||||||
|
|
||||||
NSView *contentView = window.contentView;
|
- (NSArray<NSView *> *)viewsWithIdentifier:(NSUserInterfaceItemIdentifier)identifier {
|
||||||
NSView *titlebarContainer = contentView.superview;
|
NSMutableArray<NSView *> *result = [NSMutableArray array];
|
||||||
|
if ([self.identifier isEqual:identifier]) {
|
||||||
|
[result addObject:self];
|
||||||
|
}
|
||||||
|
for (NSView *sub in self.subviews) {
|
||||||
|
[result addObjectsFromArray:[sub viewsWithIdentifier:identifier]];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
static CGFloat
|
||||||
|
title_bar_and_tool_bar_height(NSWindow *window) {
|
||||||
|
NSRect frame = window.frame;
|
||||||
|
NSRect content = [window contentRectForFrameRect:frame];
|
||||||
|
return NSHeight(frame) - NSHeight(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void clear_title_bar_background_views(NSWindow *window) {
|
||||||
|
#define tag @"kitty-for-transparent-titlebar"
|
||||||
|
NSView *contentView = window.contentView, *titlebarContainer = contentView ? contentView.superview : nil;
|
||||||
|
if (titlebarContainer) {
|
||||||
|
for (NSView *subview in [titlebarContainer viewsWithIdentifier:tag]) [subview removeFromSuperview];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_title_bar_background(NSWindow *window, NSColor *backgroundColor) {
|
||||||
|
NSView *contentView = window.contentView, *titlebarContainer = contentView ? contentView.superview : nil;
|
||||||
if (!titlebarContainer) return;
|
if (!titlebarContainer) return;
|
||||||
|
for (NSView *subview in [titlebarContainer viewsWithIdentifier:tag]) [subview removeFromSuperview];
|
||||||
|
if (!backgroundColor) return;
|
||||||
|
|
||||||
NSMutableArray *toRemove = [NSMutableArray array];
|
const CGFloat height = title_bar_and_tool_bar_height(window);
|
||||||
for (NSView *subview in titlebarContainer.subviews) {
|
NSView *bgView = [[NSView alloc] initWithFrame:NSMakeRect(
|
||||||
if ([subview isKindOfClass:NSClassFromString(@"NSVisualEffectView")]) {
|
0, titlebarContainer.bounds.size.height - height, titlebarContainer.bounds.size.width, height)];
|
||||||
[toRemove addObject:subview];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (NSView *subview in toRemove) {
|
|
||||||
[subview removeFromSuperview];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSView *bgView =
|
|
||||||
[[NSView alloc] initWithFrame:NSMakeRect(0, titlebarContainer.bounds.size.height - 28,
|
|
||||||
titlebarContainer.bounds.size.width, 28)];
|
|
||||||
bgView.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
|
bgView.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
|
||||||
bgView.wantsLayer = YES;
|
bgView.wantsLayer = YES;
|
||||||
bgView.layer.backgroundColor = backgroundColor.CGColor;
|
bgView.layer.backgroundColor = backgroundColor.CGColor;
|
||||||
|
bgView.identifier = tag;
|
||||||
|
|
||||||
NSView *containerView = [[NSView alloc] initWithFrame:window.contentView.bounds];
|
NSView *containerView = [[NSView alloc] initWithFrame:window.contentView.bounds];
|
||||||
containerView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
containerView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||||
|
containerView.identifier = tag;
|
||||||
[containerView addSubview:bgView];
|
[containerView addSubview:bgView];
|
||||||
|
[bgView release];
|
||||||
[window.contentView addSubview:containerView];
|
[window.contentView addSubview:containerView];
|
||||||
|
[containerView release];
|
||||||
|
#undef tag
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwCocoaSetWindowChrome(GLFWwindow *w, unsigned int color, bool use_system_color, unsigned int system_color, int background_blur, unsigned int hide_window_decorations, bool show_text_in_titlebar, int color_space, float background_opacity, bool resizable) { @autoreleasepool {
|
GLFWAPI void glfwCocoaSetWindowChrome(GLFWwindow *w, unsigned int color, bool use_system_color, unsigned int system_color, int background_blur, unsigned int hide_window_decorations, bool show_text_in_titlebar, int color_space, float background_opacity, bool resizable) { @autoreleasepool {
|
||||||
@@ -3291,8 +3317,8 @@ GLFWAPI void glfwCocoaSetWindowChrome(GLFWwindow *w, unsigned int color, bool us
|
|||||||
[[window->ns.object standardWindowButton: NSWindowMiniaturizeButton] setHidden:hide_titlebar_buttons];
|
[[window->ns.object standardWindowButton: NSWindowMiniaturizeButton] setHidden:hide_titlebar_buttons];
|
||||||
[[window->ns.object standardWindowButton: NSWindowZoomButton] setHidden:hide_titlebar_buttons];
|
[[window->ns.object standardWindowButton: NSWindowZoomButton] setHidden:hide_titlebar_buttons];
|
||||||
if (background_opacity < 1.0 && !window->ns.titlebar_hidden && window->decorated) {
|
if (background_opacity < 1.0 && !window->ns.titlebar_hidden && window->decorated) {
|
||||||
setTitlebarBackgroundColor(window->ns.object, [background colorUsingColorSpace:cs]);
|
set_title_bar_background(window->ns.object, [background colorUsingColorSpace:(cs ? cs : [NSColorSpace deviceRGBColorSpace])]);
|
||||||
}
|
} else clear_title_bar_background_views(window->ns.object);
|
||||||
// Apple throws a hissy fit if one attempts to clear the value of NSWindowStyleMaskFullScreen outside of a full screen transition
|
// Apple throws a hissy fit if one attempts to clear the value of NSWindowStyleMaskFullScreen outside of a full screen transition
|
||||||
// event. See https://github.com/kovidgoyal/kitty/issues/7106
|
// event. See https://github.com/kovidgoyal/kitty/issues/7106
|
||||||
NSWindowStyleMask fsmask = current_style_mask & NSWindowStyleMaskFullScreen;
|
NSWindowStyleMask fsmask = current_style_mask & NSWindowStyleMaskFullScreen;
|
||||||
|
|||||||
@@ -960,6 +960,7 @@ PYWRAP1(change_background_opacity) {
|
|||||||
WITH_OS_WINDOW(os_window_id)
|
WITH_OS_WINDOW(os_window_id)
|
||||||
os_window->background_opacity = opacity;
|
os_window->background_opacity = opacity;
|
||||||
if (!os_window->redraw_count) os_window->redraw_count++;
|
if (!os_window->redraw_count) os_window->redraw_count++;
|
||||||
|
set_os_window_chrome(os_window); // on macOS titlebar opacity can depend on background_opacity
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
END_WITH_OS_WINDOW
|
END_WITH_OS_WINDOW
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
|
|||||||
Reference in New Issue
Block a user