Skip to content

Commit

Permalink
Merge branch 'pr/1021' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrm committed Mar 26, 2024
2 parents 6e6deb5 + 597e4f1 commit b062643
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 49 deletions.
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

0 comments on commit b062643

Please sign in to comment.