Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hide MacOS titlebar #1021

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 26 additions & 44 deletions pdf_viewer/macos_specific.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,74 +17,56 @@ @implementation DraggableTitleView

// Handle mouse click events
- (void)mouseDown:(NSEvent *)event {
// double-click to zoom
if ([event clickCount] == 2) {
[self.window zoom:nil];
} else {
// drag Window
[self.window performWindowDragWithEvent:event];
}
// double-click to zoom
if ([event clickCount] == 2) {
[self.window zoom:nil];
} else {
// drag Window
[self.window performWindowDragWithEvent:event];
}
}

- (void)updateTrackingAreas {
[self initTrackingArea];
[self initTrackingArea];
}

-(void) initTrackingArea {
NSTrackingAreaOptions options = (NSTrackingActiveAlways | NSTrackingInVisibleRect |
NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);
NSTrackingAreaOptions options = (NSTrackingActiveAlways | NSTrackingInVisibleRect |
NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);

NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:options
owner:self
userInfo:nil];
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:options
owner:self
userInfo:nil];

[self addTrackingArea:area];
[self addTrackingArea:area];
}
-(void)mouseEntered:(NSEvent *)event {
if((self.window.styleMask & NSWindowStyleMaskFullScreen) == 0) {
[[self.window standardWindowButton: NSWindowCloseButton] setHidden:NO];
[[self.window standardWindowButton: NSWindowMiniaturizeButton] setHidden:NO];
[[self.window standardWindowButton: NSWindowZoomButton] setHidden:NO];
}
if((self.window.styleMask & NSWindowStyleMaskFullScreen) == 0) {
[[self.window standardWindowButton: NSWindowCloseButton] setHidden:NO];
[[self.window standardWindowButton: NSWindowMiniaturizeButton] setHidden:NO];
[[self.window standardWindowButton: NSWindowZoomButton] setHidden:NO];
}
}

-(void)mouseExited:(NSEvent *)event {
if((self.window.styleMask & NSWindowStyleMaskFullScreen) == 0) {
[[self.window standardWindowButton: NSWindowCloseButton] setHidden:YES];
[[self.window standardWindowButton: NSWindowMiniaturizeButton] setHidden:YES];
[[self.window standardWindowButton: NSWindowZoomButton] setHidden:YES];
}
if((self.window.styleMask & NSWindowStyleMaskFullScreen) == 0) {
[[self.window standardWindowButton: NSWindowCloseButton] setHidden:YES];
[[self.window standardWindowButton: NSWindowMiniaturizeButton] setHidden:YES];
[[self.window standardWindowButton: NSWindowZoomButton] setHidden:YES];
}
}

@end

extern "C" void showWindowTitleBarButtons(WId winId) {
if (winId == 0) return;
NSView* nativeView = reinterpret_cast<NSView*>(winId);
NSWindow* nativeWindow = [nativeView window];
[[nativeWindow standardWindowButton: NSWindowCloseButton] setHidden:NO];
[[nativeWindow standardWindowButton: NSWindowMiniaturizeButton] setHidden:NO];
[[nativeWindow standardWindowButton: NSWindowZoomButton] setHidden:NO];
}

extern "C" void hideWindowTitleBarButtons(WId winId) {
if (winId == 0) return;
NSView* nativeView = reinterpret_cast<NSView*>(winId);
NSWindow* nativeWindow = [nativeView window];
[[nativeWindow standardWindowButton: NSWindowCloseButton] setHidden:YES];
[[nativeWindow standardWindowButton: NSWindowMiniaturizeButton] setHidden:YES];
[[nativeWindow standardWindowButton: NSWindowZoomButton] setHidden:YES];
}

extern "C" void hideWindowTitleBar(WId winId) {
if (winId == 0) return;

NSView* nativeView = reinterpret_cast<NSView*>(winId);
NSWindow* nativeWindow = [nativeView window];

if(nativeWindow.titleVisibility == NSWindowTitleHidden){
return;
return;
}

[[nativeWindow standardWindowButton: NSWindowCloseButton] setHidden:YES];
Expand Down
8 changes: 3 additions & 5 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ extern "C" {
#ifdef Q_OS_MACOS
extern "C" void changeTitlebarColor(WId, double, double, double, double);
extern "C" void hideWindowTitleBar(WId);
extern "C" void showWindowTitleBarButtons(WId);
extern "C" void hideWindowTitleBarButtons(WId);
#endif

extern int next_window_id;
Expand Down Expand Up @@ -1229,7 +1227,7 @@ MainWidget::MainWidget(fz_context* mupdf_context,
}

if (MACOS_HIDE_TITLEBAR) {
hideWindowTitleBar(winId());
hideWindowTitleBar(winId());
}
menu_bar = create_main_menu_bar();
setMenuBar(menu_bar);
Expand Down Expand Up @@ -4075,7 +4073,7 @@ void MainWidget::apply_window_params_for_two_window_mode() {

#ifdef Q_OS_MACOS
if (MACOS_HIDE_TITLEBAR) {
hideWindowTitleBar(helper_window->winId());
hideWindowTitleBar(helper_window->winId());
}
#endif
//int main_window_width = QApplication::desktop()->screenGeometry(0).width();
Expand Down Expand Up @@ -9767,7 +9765,7 @@ void MainWidget::initialize_helper(){
#ifdef Q_OS_MACOS
QWidget* helper_window = get_top_level_widget(helper_opengl_widget_);
if (MACOS_HIDE_TITLEBAR) {
hideWindowTitleBar(helper_window->winId());
hideWindowTitleBar(helper_window->winId());
}
helper_opengl_widget_->show();
helper_opengl_widget_->hide();
Expand Down
Loading