Skip to content

Commit 5c58d15

Browse files
committed
skins[-qt]: Prompt to restart with XWayland
See accompanying change on core side: "Enable XWayland only for skinned UI"
1 parent de5e6b2 commit 5c58d15

File tree

4 files changed

+97
-6
lines changed

4 files changed

+97
-6
lines changed

src/skins-qt/plugin.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ bool QtSkins::init ()
176176
return false;
177177
}
178178

179-
if (QGuiApplication::platformName() == "wayland")
179+
if (QGuiApplication::platformName () == "wayland" &&
180+
qgetenv ("DISPLAY").isEmpty ())
180181
{
181-
AUDERR ("The Winamp interface is not supported on Wayland. "
182-
"Please run Audacious via XWayland.\n");
182+
AUDERR ("The Winamp interface is not supported on Wayland, and "
183+
"XWayland does not appear to be available on this system.\n");
183184
audqt::cleanup ();
184185
return false;
185186
}

src/skins-qt/view.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
*/
2121

2222
#include <libaudcore/hook.h>
23+
#include <libaudcore/i18n.h>
2324
#include <libaudcore/mainloop.h>
2425
#include <libaudcore/runtime.h>
26+
#include <libaudqt/libaudqt.h>
2527

28+
#include <QGuiApplication>
29+
#include <QMessageBox>
30+
#include <QPointer>
31+
#include <QPushButton>
2632
#include <QWindow>
2733

2834
#include "plugin.h"
@@ -38,8 +44,53 @@
3844
#include "view.h"
3945
#include "window.h"
4046

47+
class QuitOnCloseMessageBox : public QMessageBox
48+
{
49+
protected:
50+
void closeEvent (QCloseEvent *) override {
51+
aud_quit ();
52+
}
53+
};
54+
4155
void view_show_player (bool show)
4256
{
57+
static QPointer<QuitOnCloseMessageBox> dialog;
58+
59+
if (show && QGuiApplication::platformName () == "wayland")
60+
{
61+
if (! dialog)
62+
{
63+
dialog = new QuitOnCloseMessageBox;
64+
65+
auto restart = new QPushButton (audqt::translate_str (N_("Restart")), dialog);
66+
auto quit = new QPushButton (audqt::translate_str (N_("Quit")), dialog);
67+
68+
restart->setIcon (QIcon::fromTheme ("view-refresh"));
69+
quit->setIcon (QIcon::fromTheme ("application-exit"));
70+
71+
QObject::connect (restart, & QPushButton::clicked, aud_request_restart);
72+
QObject::connect (quit, & QPushButton::clicked, aud_quit);
73+
74+
dialog->setIcon (QMessageBox::Warning);
75+
dialog->setWindowTitle (_("Please Restart"));
76+
dialog->setText
77+
(_("The Winamp interface requires windowing system features not "
78+
"supported by Wayland. Audacious will attempt to use XWayland "
79+
"compatibility mode after restart."));
80+
81+
dialog->addButton (restart, QMessageBox::AcceptRole);
82+
dialog->addButton (quit, QMessageBox::RejectRole);
83+
dialog->setDefaultButton (restart);
84+
}
85+
86+
dialog->show ();
87+
show = false; // don't show main window
88+
}
89+
else if (dialog)
90+
{
91+
delete dialog.data ();
92+
}
93+
4394
if (show)
4495
{
4596
mainwin->show ();

src/skins/plugin.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ bool SkinnedUI::init ()
169169
audgui_init ();
170170

171171
#ifdef GDK_WINDOWING_WAYLAND
172-
if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
172+
if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()) &&
173+
! g_getenv ("DISPLAY"))
173174
{
174-
AUDERR ("The Winamp interface is not supported on Wayland. "
175-
"Please run Audacious via XWayland.\n");
175+
AUDERR ("The Winamp interface is not supported on Wayland, and "
176+
"XWayland does not appear to be available on this system.\n");
176177
audgui_cleanup ();
177178
return false;
178179
}

src/skins/view.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
*/
2121

2222
#include <libaudcore/hook.h>
23+
#include <libaudcore/i18n.h>
2324
#include <libaudcore/mainloop.h>
2425
#include <libaudcore/runtime.h>
26+
#include <libaudgui/libaudgui.h>
27+
#include <libaudgui/libaudgui-gtk.h>
28+
29+
#ifdef GDK_WINDOWING_WAYLAND
30+
#include <gdk/gdkwayland.h>
31+
#endif
2532

2633
#include "plugin.h"
2734
#include "plugin-window.h"
@@ -38,6 +45,37 @@
3845

3946
void view_show_player (bool show)
4047
{
48+
#ifdef GDK_WINDOWING_WAYLAND
49+
static GtkWidget * dialog;
50+
51+
if (show && GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
52+
{
53+
if (! dialog)
54+
{
55+
auto restart = audgui_button_new (_("Restart"), "view-refresh",
56+
[] (void *) { aud_request_restart (); }, nullptr);
57+
auto quit = audgui_button_new (_("Quit"), "application-exit",
58+
[] (void *) { aud_quit (); }, nullptr);
59+
60+
dialog = audgui_dialog_new (GTK_MESSAGE_WARNING, _("Please Restart"),
61+
_("The Winamp interface requires windowing system features not "
62+
"supported by Wayland. Audacious will attempt to use XWayland "
63+
"compatibility mode after restart."),
64+
restart, quit);
65+
66+
g_signal_connect (dialog, "delete-event", aud_quit, nullptr);
67+
g_signal_connect (dialog, "destroy", [] () { dialog = nullptr; }, nullptr);
68+
}
69+
70+
gtk_widget_show_all (dialog);
71+
show = false; // don't show main window
72+
}
73+
else if (dialog)
74+
{
75+
gtk_widget_destroy (dialog);
76+
}
77+
#endif
78+
4179
if (show)
4280
{
4381
// "Move" the window to the position it's already at. This seems

0 commit comments

Comments
 (0)