Use XCB for startup and multi-head check in KWin

Multi-head is somehow tested with Xvfb. At least the fork works and
the display variables are properly adjusted.
This commit is contained in:
Martin Gräßlin 2013-08-29 12:24:23 +02:00
parent 16fdecb495
commit 1b30755b32

View file

@ -402,14 +402,15 @@ KDE_EXPORT int kdemain(int argc, char * argv[])
mallopt(M_TRIM_THRESHOLD, 5*pagesize); mallopt(M_TRIM_THRESHOLD, 5*pagesize);
#endif // M_TRIM_THRESHOLD #endif // M_TRIM_THRESHOLD
Display* dpy = XOpenDisplay(NULL); int primaryScreen = 0;
if (!dpy) { xcb_connection_t *c = xcb_connect(nullptr, &primaryScreen);
if (!c || xcb_connection_has_error(c)) {
fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n", fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n",
argv[0], XDisplayName(NULL)); argv[0], qgetenv("DISPLAY").constData());
exit(1); exit(1);
} }
int number_of_screens = ScreenCount(dpy); const int number_of_screens = xcb_setup_roots_length(xcb_get_setup(c));
// multi head // multi head
auto isMultiHead = []() -> bool { auto isMultiHead = []() -> bool {
@ -421,11 +422,11 @@ KDE_EXPORT int kdemain(int argc, char * argv[])
}; };
if (number_of_screens != 1 && isMultiHead()) { if (number_of_screens != 1 && isMultiHead()) {
KWin::is_multihead = true; KWin::is_multihead = true;
KWin::screen_number = DefaultScreen(dpy); KWin::screen_number = primaryScreen;
int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head
QByteArray display_name = XDisplayString(dpy); QByteArray display_name = qgetenv("DISPLAY");
XCloseDisplay(dpy); xcb_disconnect(c);
dpy = 0; c = nullptr;
if ((pos = display_name.lastIndexOf('.')) != -1) if ((pos = display_name.lastIndexOf('.')) != -1)
display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s" display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s"