From 42dfcbcc0fe6019d32cd5680a86e2831fe9b6974 Mon Sep 17 00:00:00 2001 From: tpearson Date: Tue, 20 Jul 2010 20:43:38 +0000 Subject: KRandRTray fixes; minor compilation repairs git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1152360 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- krandr/libkrandr.cc | 9 +++++++++ krandr/lowlevel_randr.c | 4 ++++ krandr/randr.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+) (limited to 'krandr') diff --git a/krandr/libkrandr.cc b/krandr/libkrandr.cc index db40743a4..f2080f287 100644 --- a/krandr/libkrandr.cc +++ b/krandr/libkrandr.cc @@ -90,6 +90,9 @@ QString KRandrSimpleAPI::applyIccFile(QString screenName, QString fileName) { screenNumber = -1; randr_display = XOpenDisplay(NULL); randr_screen_info = read_screen_info(randr_display); + if (randr_screen_info == NULL) { + return ""; + } j=0; for (i = 0; i < randr_screen_info->n_output; i++) { output_info = randr_screen_info->outputs[i]->info; @@ -151,6 +154,9 @@ QString KRandrSimpleAPI::applyIccFile(QString screenName, QString fileName) { screenNumber = -1; randr_display = XOpenDisplay(NULL); randr_screen_info = read_screen_info(randr_display); + if (randr_screen_info == NULL) { + return ""; + } j=0; for (i = 0; i < randr_screen_info->n_output; i++) { output_info = randr_screen_info->outputs[i]->info; @@ -216,6 +222,9 @@ QString KRandrSimpleAPI::applyIccConfiguration(QString profileName, QString kde_ if (isValid() == true) { randr_display = XOpenDisplay(NULL); randr_screen_info = read_screen_info(randr_display); + if (randr_screen_info == NULL) { + return ""; + } for (i = 0; i < randr_screen_info->n_output; i++) { output_info = randr_screen_info->outputs[i]->info; errorstr = applyIccFile(output_info->name, getIccFileName(profileName, output_info->name, kde_confdir)); diff --git a/krandr/lowlevel_randr.c b/krandr/lowlevel_randr.c index 5326f0334..251d3bef5 100644 --- a/krandr/lowlevel_randr.c +++ b/krandr/lowlevel_randr.c @@ -384,6 +384,10 @@ struct ScreenInfo* internal_read_screen_info (Display *display) sr = XRRGetScreenResources (display, root_window); + if (sr == NULL) { + return NULL; + } + screen_info = malloc (sizeof (struct ScreenInfo)); screen_info->dpy = display; screen_info->window = root_window; diff --git a/krandr/randr.cpp b/krandr/randr.cpp index 63c5c0450..d56b37481 100644 --- a/krandr/randr.cpp +++ b/krandr/randr.cpp @@ -562,6 +562,20 @@ RandRDisplay::RandRDisplay() return; } + // Sometimes the extension is available but does not return any screens (!) + // Check for that case + Display *randr_display = XOpenDisplay(NULL); + int screen_num; + Window root_window; + + screen_num = DefaultScreen (randr_display); + root_window = RootWindow (randr_display, screen_num); + if (XRRGetScreenResources (randr_display, root_window) == NULL) { + m_errorCode = i18n("No screens detected"); + m_valid = false; + return; + } + int major_version, minor_version; XRRQueryVersion(qt_xdisplay(), &major_version, &minor_version); -- cgit v1.2.1