@@ -100,9 +100,37 @@ extern "C" {
100100
101101#ifdef Q_OS_MACOS
102102extern " C" void changeTitlebarColor (WId, double , double , double , double );
103- extern " C" void hideWindowTitleBar (WId);
104103#endif
105104
105+ static void set_titlebar_visible (QWidget* widget, bool visible, bool should_show) {
106+ if (widget == nullptr ) {
107+ return ;
108+ }
109+
110+ Qt::WindowFlags flags = widget->windowFlags ();
111+ if (visible) {
112+ flags &= ~Qt::CustomizeWindowHint;
113+ flags |= Qt::WindowContextHelpButtonHint;
114+ flags |= Qt::WindowSystemMenuHint;
115+ flags |= Qt::WindowMinMaxButtonsHint;
116+ flags |= Qt::WindowCloseButtonHint;
117+ flags |= Qt::WindowTitleHint;
118+ }
119+ else {
120+ flags |= Qt::CustomizeWindowHint;
121+ flags &= ~Qt::WindowContextHelpButtonHint;
122+ flags &= ~Qt::WindowSystemMenuHint;
123+ flags &= ~Qt::WindowMinMaxButtonsHint;
124+ flags &= ~Qt::WindowCloseButtonHint;
125+ flags &= ~Qt::WindowTitleHint;
126+ }
127+
128+ widget->setWindowFlags (flags);
129+ if (should_show) {
130+ widget->show ();
131+ }
132+ }
133+
106134extern int next_window_id;
107135
108136extern bool SHOULD_USE_MULTIPLE_MONITORS ;
@@ -1322,7 +1350,7 @@ MainWidget::MainWidget(fz_context* mupdf_context,
13221350 }
13231351
13241352 if (MACOS_HIDE_TITLEBAR ) {
1325- hideWindowTitleBar ( winId () );
1353+ set_titlebar_visible ( this , false , false );
13261354 }
13271355 menu_bar = create_main_menu_bar ();
13281356 setMenuBar (menu_bar);
@@ -4312,7 +4340,7 @@ void MainWidget::apply_window_params_for_two_window_mode() {
43124340
43134341#ifdef Q_OS_MACOS
43144342 if (MACOS_HIDE_TITLEBAR ) {
4315- hideWindowTitleBar (helper_window-> winId () );
4343+ set_titlebar_visible (helper_window, false , false );
43164344 }
43174345#endif
43184346 // int main_window_width = QApplication::desktop()->screenGeometry(0).width();
@@ -4957,28 +4985,7 @@ void MainWidget::toggle_statusbar() {
49574985}
49584986
49594987void MainWidget::toggle_titlebar () {
4960-
4961- Qt::WindowFlags flags = windowFlags ();
4962- if (flags.testFlag (Qt::WindowTitleHint)) {
4963- flags |= Qt::CustomizeWindowHint;
4964- flags &= ~Qt::WindowContextHelpButtonHint;
4965- flags &= ~Qt::WindowSystemMenuHint;
4966- flags &= ~Qt::WindowMinMaxButtonsHint;
4967- flags &= ~Qt::WindowCloseButtonHint;
4968- flags &= ~Qt::WindowTitleHint;
4969- setWindowFlags (flags);
4970-
4971- }
4972- else {
4973- flags &= ~Qt::CustomizeWindowHint;
4974- flags |= Qt::WindowContextHelpButtonHint;
4975- flags |= Qt::WindowSystemMenuHint;
4976- flags |= Qt::WindowMinMaxButtonsHint;
4977- flags |= Qt::WindowCloseButtonHint;
4978- flags |= Qt::WindowTitleHint;
4979- setWindowFlags (flags);
4980- }
4981- show ();
4988+ set_titlebar_visible (this , !windowFlags ().testFlag (Qt::WindowTitleHint), true );
49824989}
49834990
49844991
@@ -7839,6 +7846,13 @@ void MainWidget::on_configs_changed(std::vector<std::string>* config_names) {
78397846 if (confname == " macos_titlebar_color" ){
78407847 changeTitlebarColor (winId (), MACOS_TITLEBAR_COLOR [0 ], MACOS_TITLEBAR_COLOR [1 ], MACOS_TITLEBAR_COLOR [2 ], 1 .0f );
78417848 }
7849+ if (confname == " macos_hide_titlebar" ) {
7850+ set_titlebar_visible (this , !MACOS_HIDE_TITLEBAR , true );
7851+ if (helper_opengl_widget_ != nullptr ) {
7852+ QWidget* helper_window = get_top_level_widget (helper_opengl_widget_);
7853+ set_titlebar_visible (helper_window, !MACOS_HIDE_TITLEBAR , helper_window->isVisible ());
7854+ }
7855+ }
78427856#endif
78437857 if (confname == " use_system_theme" ) {
78447858 set_color_mode_to_system_theme ();
@@ -10301,7 +10315,7 @@ void MainWidget::initialize_helper(){
1030110315#ifdef Q_OS_MACOS
1030210316 QWidget* helper_window = get_top_level_widget (helper_opengl_widget_);
1030310317 if (MACOS_HIDE_TITLEBAR ) {
10304- hideWindowTitleBar (helper_window-> winId () );
10318+ set_titlebar_visible (helper_window, false , false );
1030510319 }
1030610320 helper_opengl_widget_->show ();
1030710321 helper_opengl_widget_->hide ();
0 commit comments