summaryrefslogtreecommitdiff
path: root/community/ibus-qt/0001-Do-not-crash-on-missing-invalid-DISPLAY-envvar.patch
blob: eab3a51fe4efb6e0c6b64c6292e36773fb3d970c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From fab6dc760edc39b9b4e561cfbf21b38c4fa86234 Mon Sep 17 00:00:00 2001
From: Peter Wu <lekensteyn@gmail.com>
Date: Tue, 4 Sep 2012 19:40:08 +0200
Subject: [PATCH] Do not crash on missing/invalid DISPLAY envvar.

- Check whether the passed DISPLAY environment variable contains ":".

- Fallback to "-display" parameter passed to QApplication.
---
 src/CMakeLists.txt |  2 ++
 src/qibusbus.cpp   | 23 ++++++++++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2ad5588..8866ac0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -92,9 +92,11 @@ set_target_properties(
 target_link_libraries(
     ibus-qt
     debug ${QT_QTCORE_LIBRARY_DEBUG}
+    debug ${QT_QTGUI_LIBRARY_DEBUG}
     debug ${QT_QTDBUS_LIBRARY_DEBUG}
     debug ${QT_QTXML_LIBRARY_DEBUG}
     optimized ${QT_QTCORE_LIBRARY_RELEASE}
+    optimized ${QT_QTGUI_LIBRARY_RELEASE}
     optimized ${QT_QTDBUS_LIBRARY_RELEASE}
     optimized ${QT_QTXML_LIBRARY_RELEASE}
     ${DBUS_LIBRARIES}
diff --git a/src/qibusbus.cpp b/src/qibusbus.cpp
index 6a45d65..ed8248a 100644
--- a/src/qibusbus.cpp
+++ b/src/qibusbus.cpp
@@ -12,7 +12,8 @@
 #include "qibusbus.h"
 #include "qibusibusproxy.h"
 #include "qibusdbusproxy.h"
-
+#include <X11/Xlib.h>
+#include <QX11Info>
 
 namespace IBus {
 /**
@@ -121,15 +122,23 @@ QString
 Bus::getSocketPath (void)
 {
     QString display = getenv ("DISPLAY");
-    QStringList strs = display.split(":");
     QString hostname = "unix";
     QString display_number = "0";
+    /* fallback when -display is passed to QApplication with no DISPLAY env */
+    if (display == NULL) {
+        Display * dpy = QX11Info::display();
+        if (dpy)
+            display = XDisplayString(dpy);
+    }
+    if (display != NULL && display.contains(':')) {
+        QStringList strs = display.split(":");
 
-    if (!strs[0].isEmpty())
-        hostname = strs[0];
-    strs = strs[1].split(".");
-    if (!strs[0].isEmpty())
-        display_number = strs[0];
+        if (!strs[0].isEmpty())
+            hostname = strs[0];
+        strs = strs[1].split(".");
+        if (!strs[0].isEmpty())
+            display_number = strs[0];
+    }
 
     QString path =
         QDir::homePath() +
-- 
1.7.12