summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2018-08-24 22:41:29 +0200
committerHein-Pieter van Braam <hp@tmm.cx>2018-08-25 00:53:45 +0200
commitc8464eb69f97bba44000e596b80f3cd56dba940f (patch)
tree2ecfd3dcee39ef1177eca25565b8cabd4a001e3f
parent6ce4078c5fdc5d9f855ea49b3382f2763a73e19b (diff)
Support more X11 dialogs for X11::alert()
Modern distributions such as Fedora do not ship 'xdialog' with their default deployment. This commit adds support for Gnome's Zenity as well as KDE's kdialog.
-rw-r--r--platform/x11/os_x11.cpp64
1 files changed, 59 insertions, 5 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 56b0c975c4..ca9fd68412 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -2564,14 +2564,68 @@ void OS_X11::swap_buffers() {
}
void OS_X11::alert(const String &p_alert, const String &p_title) {
+ const char *message_programs[] = { "zenity", "kdialog", "Xdialog", "xmessage" };
+
+ String path = get_environment("PATH");
+ Vector<String> path_elems = path.split(":", false);
+ String program;
+
+ for (int i = 0; i < path_elems.size(); i++) {
+ for (unsigned int k = 0; k < sizeof(message_programs) / sizeof(char *); k++) {
+ String tested_path = path_elems[i] + "/" + message_programs[k];
+
+ if (FileAccess::exists(tested_path)) {
+ program = tested_path;
+ break;
+ }
+ }
+
+ if (program.length())
+ break;
+ }
List<String> args;
- args.push_back("-center");
- args.push_back("-title");
- args.push_back(p_title);
- args.push_back(p_alert);
- execute("xmessage", args, true);
+ if (program.ends_with("zenity")) {
+ args.push_back("--error");
+ args.push_back("--width");
+ args.push_back("500");
+ args.push_back("--title");
+ args.push_back(p_title);
+ args.push_back("--text");
+ args.push_back(p_alert);
+ }
+
+ if (program.ends_with("kdialog")) {
+ args.push_back("--error");
+ args.push_back(p_alert);
+ args.push_back("--title");
+ args.push_back(p_title);
+ }
+
+ if (program.ends_with("Xdialog")) {
+ args.push_back("--title");
+ args.push_back(p_title);
+ args.push_back("--msgbox");
+ args.push_back(p_alert);
+ args.push_back("0");
+ args.push_back("0");
+ }
+
+ if (program.ends_with("xmessage")) {
+ args.push_back("-center");
+ args.push_back("-title");
+ args.push_back(p_title);
+ args.push_back(p_alert);
+ }
+
+ if (program.length()) {
+ execute(program, args, true);
+ } else {
+ print_line(p_alert);
+ }
+
+ return;
}
void OS_X11::set_icon(const Ref<Image> &p_icon) {