You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1635 lines
53 KiB
1635 lines
53 KiB
12 years ago
|
/* libtderandr.cc - class KRandr that makes it easy to use XRandr in KDE
|
||
15 years ago
|
This file is part of KRandr 0.9.5
|
||
|
Copyright (C) 2010 Timothy Pearson
|
||
14 years ago
|
LibKRandr's homepage : http://www.trinitydesktop.org
|
||
15 years ago
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
Send comments and bug fixes to Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||
|
|
||
|
***************************************************************************/
|
||
|
|
||
12 years ago
|
#include <tqdir.h>
|
||
13 years ago
|
#include <tqtimer.h>
|
||
|
#include <tqstringlist.h>
|
||
|
|
||
|
#include <klocale.h>
|
||
13 years ago
|
#include <kmessagebox.h>
|
||
13 years ago
|
#include <kapplication.h>
|
||
|
|
||
13 years ago
|
#include <stdlib.h>
|
||
12 years ago
|
#include <unistd.h>
|
||
13 years ago
|
#include <cmath>
|
||
13 years ago
|
|
||
12 years ago
|
#include "libtderandr.h"
|
||
15 years ago
|
|
||
13 years ago
|
#include <X11/extensions/dpms.h>
|
||
|
|
||
13 years ago
|
// FIXME
|
||
|
// For now, just use the standalone xrandr program to apply the display settings
|
||
|
#define USE_XRANDR_PROGRAM
|
||
|
|
||
13 years ago
|
// This routine is courtsey of an answer on "Stack Overflow"
|
||
|
// It takes an LSB-first int and makes it an MSB-first int (or vice versa)
|
||
|
unsigned int reverse_bits(register unsigned int x)
|
||
|
{
|
||
|
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
|
||
|
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
|
||
|
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
|
||
|
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
|
||
|
return((x >> 16) | (x << 16));
|
||
|
}
|
||
|
|
||
13 years ago
|
// This routine returns the output of an arbitrary Bash command
|
||
|
TQString exec(const char * cmd) {
|
||
|
TQString bashcommand = cmd;
|
||
|
bashcommand = bashcommand.replace("\"", "\\\"");
|
||
13 years ago
|
bashcommand = TQString("/bin/bash -c \"%1\" 2>&1").arg(bashcommand);
|
||
13 years ago
|
FILE* pipe = popen(bashcommand.ascii(), "r");
|
||
|
if (!pipe) return "ERROR";
|
||
|
char buffer[128];
|
||
|
TQString result = "";
|
||
|
while(!feof(pipe)) {
|
||
|
if(fgets(buffer, 128, pipe) != NULL) {
|
||
|
result += buffer;
|
||
|
}
|
||
|
}
|
||
|
pclose(pipe);
|
||
|
result.remove(result.length(), 1);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQString capitalizeString(TQString in) {
|
||
|
return in.left(1).upper() + in.right(in.length()-1);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::getIccFileName(TQString profileName, TQString screenName, TQString kde_confdir) {
|
||
12 years ago
|
KSimpleConfig *t_config = NULL;
|
||
|
KSimpleConfig *t_systemconfig = NULL;
|
||
15 years ago
|
int t_numberOfProfiles;
|
||
15 years ago
|
TQStringList t_cfgProfiles;
|
||
|
TQString retval;
|
||
15 years ago
|
|
||
|
if (profileName != NULL) {
|
||
13 years ago
|
t_config = new KSimpleConfig( TQString::fromLatin1( "kiccconfigrc" ));
|
||
15 years ago
|
}
|
||
|
else {
|
||
15 years ago
|
t_systemconfig = new KSimpleConfig( kde_confdir + TQString("/kicc/kiccconfigrc") );
|
||
15 years ago
|
}
|
||
|
|
||
|
if (profileName != NULL) {
|
||
|
t_config->setGroup(NULL);
|
||
|
if (t_config->readBoolEntry("EnableICC", false) == true) {
|
||
|
t_config->setGroup(profileName);
|
||
|
retval = t_config->readEntry(screenName);
|
||
|
}
|
||
|
else {
|
||
|
retval = "";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
t_systemconfig->setGroup(NULL);
|
||
|
if (t_systemconfig->readBoolEntry("EnableICC", false) == true) {
|
||
|
retval = t_systemconfig->readEntry("ICCFile");
|
||
|
}
|
||
|
else {
|
||
|
retval = "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (profileName != "") {
|
||
12 years ago
|
if (t_config) {
|
||
|
delete t_config;
|
||
|
}
|
||
15 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
if (t_systemconfig) {
|
||
|
delete t_systemconfig;
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::applyIccFile(TQString screenName, TQString fileName) {
|
||
15 years ago
|
int i;
|
||
|
int j;
|
||
|
Display *randr_display;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
XRROutputInfo *output_info;
|
||
|
|
||
|
int screenNumber = 0;
|
||
|
|
||
|
if (fileName != "") {
|
||
|
// FIXME
|
||
|
// This should use the RRSetCrtcGamma function when available
|
||
|
// That is the only way to get proper setting when two output are active at the same time
|
||
|
// (otherwise in clone mode only one screen is available)
|
||
|
|
||
|
// HACK
|
||
|
// For now, simply exit with no changes if screenName is not an active output
|
||
|
|
||
|
if (isValid() == true) {
|
||
|
screenNumber = -1;
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
15 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
15 years ago
|
if (randr_screen_info == NULL) {
|
||
|
return "";
|
||
|
}
|
||
15 years ago
|
j=0;
|
||
|
for (i = 0; i < randr_screen_info->n_output; i++) {
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
// Look for ON outputs...
|
||
|
if (!randr_screen_info->outputs[i]->cur_crtc) {
|
||
|
continue;
|
||
|
}
|
||
|
// ...that are connected
|
||
|
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
|
||
|
continue;
|
||
|
}
|
||
|
if (output_info->name == screenName) {
|
||
|
screenNumber = j;
|
||
|
}
|
||
|
j++;
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (screenNumber >= 0) {
|
||
|
// Apply ICC settings with XCalib
|
||
15 years ago
|
TQString icc_command;
|
||
15 years ago
|
FILE *pipe_xcalib;
|
||
|
char xcalib_result[2048];
|
||
|
int i;
|
||
|
xcalib_result[0]=0;
|
||
|
|
||
14 years ago
|
icc_command = TQString("xcalib \"%1\"").arg(fileName);
|
||
15 years ago
|
if ((pipe_xcalib = popen(icc_command.ascii(), "r")) == NULL)
|
||
|
{
|
||
12 years ago
|
printf("Xcalib pipe error\n\r [xcalib apply]");
|
||
15 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
if (fgets(xcalib_result, 2048, pipe_xcalib)) {
|
||
|
pclose(pipe_xcalib);
|
||
|
for (i=1;i<2048;i++) {
|
||
|
if (xcalib_result[i] == 0) {
|
||
|
xcalib_result[i-1]=0;
|
||
|
i=2048;
|
||
|
}
|
||
|
}
|
||
|
if (strlen(xcalib_result) > 2) {
|
||
|
return xcalib_result;
|
||
15 years ago
|
}
|
||
|
}
|
||
12 years ago
|
else {
|
||
12 years ago
|
return "";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
// Reset ICC profile on this screen
|
||
|
|
||
|
// FIXME
|
||
|
// This should use the RRSetCrtcGamma function when available
|
||
|
// That is the only way to get proper setting when two output are active at the same time
|
||
|
// (otherwise in clone mode only one screen is available)
|
||
|
|
||
|
// HACK
|
||
|
// For now, simply exit with no changes if screenName is not an active output
|
||
|
|
||
|
if (isValid() == true) {
|
||
|
screenNumber = -1;
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
15 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
15 years ago
|
if (randr_screen_info == NULL) {
|
||
|
return "";
|
||
|
}
|
||
15 years ago
|
j=0;
|
||
|
for (i = 0; i < randr_screen_info->n_output; i++) {
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
// Look for ON outputs...
|
||
|
if (!randr_screen_info->outputs[i]->cur_crtc) {
|
||
|
continue;
|
||
|
}
|
||
|
// ...that are connected
|
||
|
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
|
||
|
continue;
|
||
|
}
|
||
|
if (output_info->name == screenName) {
|
||
|
screenNumber = j;
|
||
|
}
|
||
|
j++;
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (screenNumber >= 0) {
|
||
|
// Apply ICC settings with XCalib
|
||
15 years ago
|
TQString icc_command;
|
||
15 years ago
|
FILE *pipe_xcalib;
|
||
|
char xcalib_result[2048];
|
||
|
int i;
|
||
|
xcalib_result[0]=0;
|
||
|
|
||
15 years ago
|
icc_command = TQString("xcalib -c");
|
||
15 years ago
|
if ((pipe_xcalib = popen(icc_command.ascii(), "r")) == NULL)
|
||
|
{
|
||
12 years ago
|
printf("Xcalib pipe error\n\r [xcalib clear]");
|
||
15 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
if (fgets(xcalib_result, 2048, pipe_xcalib)) {
|
||
|
pclose(pipe_xcalib);
|
||
|
for (i=1;i<2048;i++) {
|
||
|
if (xcalib_result[i] == 0) {
|
||
|
xcalib_result[i-1]=0;
|
||
|
i=2048;
|
||
|
}
|
||
|
}
|
||
|
if (strlen(xcalib_result) > 2) {
|
||
|
return xcalib_result;
|
||
15 years ago
|
}
|
||
|
}
|
||
12 years ago
|
else {
|
||
12 years ago
|
return "";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::applyIccConfiguration(TQString profileName, TQString kde_confdir) {
|
||
15 years ago
|
int i;
|
||
|
Display *randr_display;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
XRROutputInfo *output_info;
|
||
15 years ago
|
KSimpleConfig *t_config;
|
||
15 years ago
|
|
||
|
int screenNumber = 0;
|
||
15 years ago
|
TQString errorstr = "";
|
||
15 years ago
|
|
||
13 years ago
|
t_config = new KSimpleConfig( TQString::fromLatin1( "kiccconfigrc" ));
|
||
15 years ago
|
|
||
15 years ago
|
// Find all screens
|
||
|
if (isValid() == true) {
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
15 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
15 years ago
|
if (randr_screen_info == NULL) {
|
||
|
return "";
|
||
|
}
|
||
15 years ago
|
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));
|
||
|
if (errorstr != "") {
|
||
|
return errorstr;
|
||
|
}
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
15 years ago
|
}
|
||
|
else {
|
||
|
return applyIccFile(getIccFileName(profileName, "Default", kde_confdir), "Default");
|
||
|
}
|
||
15 years ago
|
|
||
|
t_config->writeEntry("CurrentProfile", profileName);
|
||
|
t_config->sync();
|
||
|
delete t_config;
|
||
|
|
||
15 years ago
|
return "";
|
||
|
}
|
||
|
|
||
13 years ago
|
TQString KRandrSimpleAPI::getEDIDMonitorName(int card, TQString displayname) {
|
||
|
TQString edid;
|
||
13 years ago
|
TQByteArray binaryedid = getEDID(card, displayname);
|
||
13 years ago
|
if (binaryedid.isNull())
|
||
|
return TQString();
|
||
|
|
||
|
// Get the manufacturer ID
|
||
|
unsigned char letter_1 = ((binaryedid[8]>>2) & 0x1F) + 0x40;
|
||
|
unsigned char letter_2 = (((binaryedid[8] & 0x03) << 3) | ((binaryedid[9]>>5) & 0x07)) + 0x40;
|
||
|
unsigned char letter_3 = (binaryedid[9] & 0x1F) + 0x40;
|
||
|
TQChar qletter_1 = TQChar(letter_1);
|
||
|
TQChar qletter_2 = TQChar(letter_2);
|
||
|
TQChar qletter_3 = TQChar(letter_3);
|
||
|
TQString manufacturer_id = TQString("%1%2%3").arg(qletter_1).arg(qletter_2).arg(qletter_3);
|
||
|
|
||
|
// Get the model ID
|
||
|
unsigned int raw_model_id = (((binaryedid[10] << 8) | binaryedid[11]) << 16) & 0xFFFF0000;
|
||
|
// Reverse the bit order
|
||
|
unsigned int model_id = reverse_bits(raw_model_id);
|
||
|
|
||
|
// Try to get the model name
|
||
|
bool has_friendly_name = false;
|
||
|
unsigned char descriptor_block[18];
|
||
|
int i;
|
||
|
for (i=72;i<90;i++) {
|
||
|
descriptor_block[i-72] = binaryedid[i] & 0xFF;
|
||
|
}
|
||
|
if ((descriptor_block[0] != 0) || (descriptor_block[1] != 0) || (descriptor_block[3] != 0xFC)) {
|
||
|
for (i=90;i<108;i++) {
|
||
|
descriptor_block[i-90] = binaryedid[i] & 0xFF;
|
||
|
}
|
||
|
if ((descriptor_block[0] != 0) || (descriptor_block[1] != 0) || (descriptor_block[3] != 0xFC)) {
|
||
|
for (i=108;i<126;i++) {
|
||
|
descriptor_block[i-108] = binaryedid[i] & 0xFF;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TQString monitor_name;
|
||
|
if ((descriptor_block[0] == 0) && (descriptor_block[1] == 0) && (descriptor_block[3] == 0xFC)) {
|
||
|
char* pos = strchr((char *)(descriptor_block+5), '\n');
|
||
|
if (pos) {
|
||
|
*pos = 0;
|
||
|
has_friendly_name = true;
|
||
|
monitor_name = TQString((char *)(descriptor_block+5));
|
||
|
}
|
||
|
else {
|
||
|
has_friendly_name = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// [FIXME]
|
||
|
// Look up manudacturer names if possible!
|
||
|
|
||
|
if (has_friendly_name)
|
||
|
edid = TQString("%1 %2").arg(manufacturer_id).arg(monitor_name);
|
||
|
else
|
||
|
edid = TQString("%1 0x%2").arg(manufacturer_id).arg(model_id, 0, 16);
|
||
|
|
||
|
return edid;
|
||
|
}
|
||
|
|
||
|
TQByteArray KRandrSimpleAPI::getEDID(int card, TQString displayname) {
|
||
|
TQFile file(TQString("/sys/class/drm/card%1-%2/edid").arg(card).arg(displayname));
|
||
|
if (!file.open (IO_ReadOnly))
|
||
|
return TQByteArray();
|
||
|
TQByteArray binaryedid = file.readAll();
|
||
|
file.close();
|
||
|
return binaryedid;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::getCurrentProfile () {
|
||
|
TQString profileName;
|
||
15 years ago
|
KSimpleConfig *t_config;
|
||
|
|
||
13 years ago
|
t_config = new KSimpleConfig( TQString::fromLatin1( "kiccconfigrc" ));
|
||
15 years ago
|
profileName = t_config->readEntry("CurrentProfile");
|
||
|
delete t_config;
|
||
|
return profileName;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::applySystemWideIccConfiguration(TQString kde_confdir) {
|
||
15 years ago
|
// Apply ICC settings with XCalib
|
||
15 years ago
|
TQString icc_command;
|
||
15 years ago
|
FILE *pipe_xcalib;
|
||
|
char xcalib_result[2048];
|
||
|
int i;
|
||
|
xcalib_result[0]=0;
|
||
|
|
||
14 years ago
|
icc_command = TQString("xcalib \"%1\"").arg(getIccFileName(NULL, "Default", kde_confdir));
|
||
15 years ago
|
if ((pipe_xcalib = popen(icc_command.ascii(), "r")) == NULL)
|
||
|
{
|
||
12 years ago
|
printf("Xcalib pipe error [xcalib apply]\n\r");
|
||
15 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
if (fgets(xcalib_result, 2048, pipe_xcalib)) {
|
||
|
pclose(pipe_xcalib);
|
||
|
for (i=1;i<2048;i++) {
|
||
|
if (xcalib_result[i] == 0) {
|
||
|
xcalib_result[i-1]=0;
|
||
|
i=2048;
|
||
|
}
|
||
|
}
|
||
|
if (strlen(xcalib_result) > 2) {
|
||
|
return xcalib_result;
|
||
15 years ago
|
}
|
||
|
}
|
||
12 years ago
|
else {
|
||
12 years ago
|
return "";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
12 years ago
|
TQStringList KRandrSimpleAPI::getDisplayConfigurationProfiles(TQString kde_confdir) {
|
||
|
TQStringList ret;
|
||
|
|
||
|
TQDir d(kde_confdir + "/displayconfig/");
|
||
|
d.setFilter(TQDir::Files);
|
||
|
d.setSorting(TQDir::Name);
|
||
|
|
||
|
const TQFileInfoList *list = d.entryInfoList();
|
||
12 years ago
|
if (list) {
|
||
|
TQFileInfoListIterator it(*list);
|
||
|
TQFileInfo *fi;
|
||
12 years ago
|
|
||
12 years ago
|
while ((fi = it.current()) != 0) {
|
||
|
if (fi->fileName() != "default") {
|
||
|
ret.append(fi->fileName());
|
||
|
}
|
||
|
++it;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
bool KRandrSimpleAPI::deleteDisplayConfiguration(TQString profilename, TQString kde_confdir) {
|
||
|
TQString fileName = kde_confdir + "/displayconfig/";
|
||
|
fileName.append(profilename);
|
||
|
return (!unlink(fileName.ascii()));
|
||
|
}
|
||
|
|
||
|
bool KRandrSimpleAPI::renameDisplayConfiguration(TQString profilename, TQString newprofilename, TQString kde_confdir) {
|
||
|
TQString fileName = kde_confdir + "/displayconfig/";
|
||
|
TQString newFileName = fileName;
|
||
|
fileName.append(profilename);
|
||
|
newFileName.append(newprofilename);
|
||
|
TQDir d(kde_confdir + "/displayconfig/");
|
||
|
return (d.rename(fileName, newFileName));
|
||
|
}
|
||
|
|
||
12 years ago
|
void KRandrSimpleAPI::saveDisplayConfiguration(bool enable, bool applyonstart, TQString profilename, TQString defaultprofilename, TQString kde_confdir, TQPtrList<SingleScreenData> screenInfoArray) {
|
||
13 years ago
|
int i;
|
||
|
|
||
|
TQString filename;
|
||
13 years ago
|
|
||
|
filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
display_config->setGroup("General");
|
||
12 years ago
|
display_config->writeEntry("EnableDisplayControl", enable);
|
||
|
display_config->writeEntry("ApplySettingsOnStart", applyonstart);
|
||
12 years ago
|
display_config->writeEntry("StartupProfileName", defaultprofilename);
|
||
13 years ago
|
display_config->sync();
|
||
|
delete display_config;
|
||
|
|
||
13 years ago
|
filename = profilename;
|
||
12 years ago
|
if (filename == "") {
|
||
13 years ago
|
filename = "default";
|
||
12 years ago
|
}
|
||
13 years ago
|
filename.prepend(kde_confdir.append("/displayconfig/"));
|
||
|
|
||
13 years ago
|
display_config = new KSimpleConfig( filename );
|
||
13 years ago
|
|
||
|
i=0;
|
||
|
SingleScreenData *screendata;
|
||
|
for ( screendata=screenInfoArray.first(); screendata; screendata=screenInfoArray.next() ) {
|
||
|
display_config->setGroup(TQString("SCREEN %1").arg(i));
|
||
12 years ago
|
display_config->writeEntry("ScreenUniqueName", screendata->screenUniqueName);
|
||
13 years ago
|
display_config->writeEntry("ScreenFriendlyName", screendata->screenFriendlyName);
|
||
|
display_config->writeEntry("GenericScreenDetected", screendata->generic_screen_detected);
|
||
|
display_config->writeEntry("ScreenConnected", screendata->screen_connected);
|
||
|
display_config->writeEntry("Resolutions", screendata->resolutions);
|
||
|
display_config->writeEntry("RefreshRates", screendata->refresh_rates);
|
||
|
display_config->writeEntry("ColorDepths", screendata->color_depths);
|
||
|
display_config->writeEntry("AvailableRotations", screendata->rotations);
|
||
|
display_config->writeEntry("CurrentResolution", screendata->current_resolution_index);
|
||
|
display_config->writeEntry("CurrentRefreshRate", screendata->current_refresh_rate_index);
|
||
|
display_config->writeEntry("CurrentColorDepth", screendata->current_color_depth_index);
|
||
|
display_config->writeEntry("CurrentRotation", screendata->current_rotation_index);
|
||
|
display_config->writeEntry("CurrentOrientiation", screendata->current_orientation_mask);
|
||
13 years ago
|
display_config->writeEntry("GammaRed", screendata->gamma_red);
|
||
|
display_config->writeEntry("GammaGreen", screendata->gamma_green);
|
||
|
display_config->writeEntry("GammaBlue", screendata->gamma_blue);
|
||
13 years ago
|
display_config->writeEntry("CurrentXFlip", screendata->has_x_flip);
|
||
|
display_config->writeEntry("CurrentYFlip", screendata->has_y_flip);
|
||
|
display_config->writeEntry("SupportsTransformation", screendata->supports_transformations);
|
||
|
display_config->writeEntry("IsPrimary", screendata->is_primary);
|
||
|
display_config->writeEntry("IsExtended", screendata->is_extended);
|
||
|
display_config->writeEntry("AbsXPos", screendata->absolute_x_position);
|
||
|
display_config->writeEntry("AbsYPos", screendata->absolute_y_position);
|
||
|
display_config->writeEntry("CurrentXPixelCount", screendata->current_x_pixel_count);
|
||
|
display_config->writeEntry("CurrentYPixelCount", screendata->current_y_pixel_count);
|
||
13 years ago
|
display_config->writeEntry("HasDPMS", screendata->has_dpms);
|
||
|
display_config->writeEntry("EnableDPMS", screendata->enable_dpms);
|
||
|
display_config->writeEntry("DPMSStandbyDelay", screendata->dpms_standby_delay);
|
||
|
display_config->writeEntry("DPMSSuspendDelay", screendata->dpms_suspend_delay);
|
||
|
display_config->writeEntry("DPMSPowerDownDelay", screendata->dpms_off_delay);
|
||
13 years ago
|
i++;
|
||
|
}
|
||
|
|
||
|
display_config->sync();
|
||
|
delete display_config;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQPoint KRandrSimpleAPI::applyStartupDisplayConfiguration(TQString kde_confdir) {
|
||
|
bool applyonstart = getDisplayConfigurationStartupAutoApplyEnabled(kde_confdir);
|
||
|
if (applyonstart) {
|
||
|
TQString profilename = getDisplayConfigurationStartupAutoApplyName(kde_confdir);
|
||
|
return applyDisplayConfiguration(profilename, kde_confdir);
|
||
|
}
|
||
|
else {
|
||
|
return TQPoint();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TQPoint KRandrSimpleAPI::applyDisplayConfiguration(TQString profilename, TQString kde_confdir) {
|
||
13 years ago
|
TQPoint ret;
|
||
|
|
||
12 years ago
|
bool enabled = getDisplayConfigurationEnabled(kde_confdir);
|
||
12 years ago
|
if (profilename == "") {
|
||
12 years ago
|
profilename = "default";
|
||
12 years ago
|
}
|
||
13 years ago
|
|
||
|
if (enabled) {
|
||
|
TQPtrList<SingleScreenData> screenInfoArray;
|
||
12 years ago
|
screenInfoArray = loadDisplayConfiguration(profilename, kde_confdir);
|
||
13 years ago
|
if (screenInfoArray.count() > 0) {
|
||
12 years ago
|
applyDisplayConfiguration(screenInfoArray, FALSE, kde_confdir);
|
||
13 years ago
|
}
|
||
13 years ago
|
destroyScreenInformationObject(screenInfoArray);
|
||
|
screenInfoArray = readCurrentDisplayConfiguration();
|
||
|
ensureMonitorDataConsistency(screenInfoArray);
|
||
13 years ago
|
ret = primaryScreenOffsetFromTLC(screenInfoArray);
|
||
13 years ago
|
destroyScreenInformationObject(screenInfoArray);
|
||
|
}
|
||
13 years ago
|
|
||
|
return ret;
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
TQPtrList<SingleScreenData> KRandrSimpleAPI::loadDisplayConfiguration(TQString profilename, TQString kde_confdir) {
|
||
13 years ago
|
int i;
|
||
|
|
||
|
TQString filename;
|
||
|
filename = profilename;
|
||
12 years ago
|
if (filename == "") {
|
||
13 years ago
|
filename = "default";
|
||
12 years ago
|
}
|
||
13 years ago
|
filename.prepend(kde_confdir.append("/displayconfig/"));
|
||
|
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
|
||
13 years ago
|
TQStringList grouplist = display_config->groupList();
|
||
13 years ago
|
SingleScreenData *screendata;
|
||
|
TQPtrList<SingleScreenData> screenInfoArray;
|
||
|
for ( TQStringList::Iterator it = grouplist.begin(); it != grouplist.end(); ++it ) {
|
||
|
if ((*it).startsWith("SCREEN ")) {
|
||
|
display_config->setGroup(*it);
|
||
|
i = ((*it).remove("SCREEN ")).toInt();
|
||
|
screendata = new SingleScreenData;
|
||
|
screenInfoArray.append(screendata);
|
||
12 years ago
|
screendata->screenUniqueName = display_config->readEntry("ScreenUniqueName");
|
||
13 years ago
|
screendata->screenFriendlyName = display_config->readEntry("ScreenFriendlyName");
|
||
|
screendata->generic_screen_detected = display_config->readBoolEntry("GenericScreenDetected");
|
||
|
screendata->screen_connected = display_config->readBoolEntry("ScreenConnected");
|
||
|
screendata->resolutions = display_config->readListEntry("Resolutions");
|
||
|
screendata->refresh_rates = display_config->readListEntry("RefreshRates");
|
||
|
screendata->color_depths = display_config->readListEntry("ColorDepths");
|
||
|
screendata->rotations = display_config->readListEntry("AvailableRotations");
|
||
|
screendata->current_resolution_index = display_config->readNumEntry("CurrentResolution");
|
||
|
screendata->current_refresh_rate_index = display_config->readNumEntry("CurrentRefreshRate");
|
||
|
screendata->current_color_depth_index = display_config->readNumEntry("CurrentColorDepth");
|
||
|
screendata->current_rotation_index = display_config->readNumEntry("CurrentRotation");
|
||
|
screendata->current_orientation_mask = display_config->readNumEntry("CurrentOrientiation");
|
||
13 years ago
|
screendata->gamma_red = display_config->readDoubleNumEntry("GammaRed");
|
||
|
screendata->gamma_green = display_config->readDoubleNumEntry("GammaGreen");
|
||
|
screendata->gamma_blue = display_config->readDoubleNumEntry("GammaBlue");
|
||
13 years ago
|
screendata->has_x_flip = display_config->readBoolEntry("CurrentXFlip");
|
||
|
screendata->has_y_flip = display_config->readBoolEntry("CurrentYFlip");
|
||
|
screendata->supports_transformations = display_config->readBoolEntry("SupportsTransformation");
|
||
|
screendata->is_primary = display_config->readBoolEntry("IsPrimary");
|
||
|
screendata->is_extended = display_config->readBoolEntry("IsExtended");
|
||
|
screendata->absolute_x_position = display_config->readNumEntry("AbsXPos");
|
||
|
screendata->absolute_y_position = display_config->readNumEntry("AbsYPos");
|
||
|
screendata->current_x_pixel_count = display_config->readNumEntry("CurrentXPixelCount");
|
||
|
screendata->current_y_pixel_count = display_config->readNumEntry("CurrentYPixelCount");
|
||
13 years ago
|
screendata->has_dpms = display_config->readBoolEntry("HasDPMS");
|
||
|
screendata->enable_dpms = display_config->readBoolEntry("EnableDPMS");
|
||
|
screendata->dpms_standby_delay = display_config->readNumEntry("DPMSStandbyDelay");
|
||
|
screendata->dpms_suspend_delay = display_config->readNumEntry("DPMSSuspendDelay");
|
||
|
screendata->dpms_off_delay = display_config->readNumEntry("DPMSPowerDownDelay");
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
delete display_config;
|
||
|
|
||
|
return screenInfoArray;
|
||
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::getHardwareRotationFlags(SingleScreenData* screendata) {
|
||
|
int rotationFlags = 0;
|
||
|
TQString rotationDesired = *screendata->rotations.at(screendata->current_rotation_index);
|
||
12 years ago
|
if (rotationDesired == ROTATION_0_DEGREES_STRING) {
|
||
13 years ago
|
rotationFlags = rotationFlags | RandRScreen::Rotate0;
|
||
|
}
|
||
12 years ago
|
else if (rotationDesired == ROTATION_90_DEGREES_STRING) {
|
||
13 years ago
|
rotationFlags = rotationFlags | RandRScreen::Rotate90;
|
||
|
}
|
||
12 years ago
|
else if (rotationDesired == ROTATION_180_DEGREES_STRING) {
|
||
13 years ago
|
rotationFlags = rotationFlags | RandRScreen::Rotate180;
|
||
|
}
|
||
12 years ago
|
else if (rotationDesired == ROTATION_270_DEGREES_STRING) {
|
||
13 years ago
|
rotationFlags = rotationFlags | RandRScreen::Rotate270;
|
||
|
}
|
||
|
if (screendata->has_x_flip) {
|
||
|
rotationFlags = rotationFlags | RandRScreen::ReflectX;
|
||
|
}
|
||
|
if (screendata->has_y_flip) {
|
||
|
rotationFlags = rotationFlags | RandRScreen::ReflectY;
|
||
|
}
|
||
|
return rotationFlags;
|
||
|
}
|
||
|
|
||
13 years ago
|
#define USE_XRANDR_PROGRAM
|
||
|
|
||
12 years ago
|
bool KRandrSimpleAPI::applyDisplayConfiguration(TQPtrList<SingleScreenData> screenInfoArray, bool test, TQString kde_confdir) {
|
||
13 years ago
|
int i;
|
||
|
int j;
|
||
|
bool accepted = true;
|
||
|
Display *randr_display;
|
||
|
XRROutputInfo *output_info;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
|
||
|
SingleScreenData *screendata;
|
||
|
|
||
|
TQPtrList<SingleScreenData> oldconfig;
|
||
|
if (test == TRUE) {
|
||
|
oldconfig = readCurrentDisplayConfiguration();
|
||
|
}
|
||
|
|
||
|
if (isValid() == true) {
|
||
13 years ago
|
#ifdef USE_XRANDR_PROGRAM
|
||
|
// Assemble the command string for xrandr
|
||
|
TQString command;
|
||
|
command = "xrandr";
|
||
|
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
13 years ago
|
if (screendata) {
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
command.append(" --output ").append(output_info->name);
|
||
|
if (screendata->is_primary || screendata->is_extended) {
|
||
|
command.append(TQString(" --mode %1x%2").arg(screendata->current_x_pixel_count).arg(screendata->current_y_pixel_count));
|
||
|
command.append(TQString(" --pos %1x%2").arg(screendata->absolute_x_position).arg(screendata->absolute_y_position));
|
||
|
command.append(TQString(" --refresh %1").arg((*screendata->refresh_rates.at(screendata->current_refresh_rate_index)).replace("Hz", "")));
|
||
|
command.append(TQString(" --gamma %1:%2:%3").arg(screendata->gamma_red).arg(screendata->gamma_green).arg(screendata->gamma_blue));
|
||
|
if (screendata->current_rotation_index == 0) command.append(" --rotate ").append("normal");
|
||
|
if (screendata->current_rotation_index == 1) command.append(" --rotate ").append("left");
|
||
|
if (screendata->current_rotation_index == 2) command.append(" --rotate ").append("inverted");
|
||
|
if (screendata->current_rotation_index == 3) command.append(" --rotate ").append("right");
|
||
|
if ((screendata->has_x_flip == 0) && (screendata->has_y_flip == 0)) command.append(" --reflect ").append("normal");
|
||
|
if ((screendata->has_x_flip == 1) && (screendata->has_y_flip == 0)) command.append(" --reflect ").append("x");
|
||
|
if ((screendata->has_x_flip == 0) && (screendata->has_y_flip == 1)) command.append(" --reflect ").append("y");
|
||
|
if ((screendata->has_x_flip == 1) && (screendata->has_y_flip == 1)) command.append(" --reflect ").append("xy");
|
||
|
if (screendata->is_primary) {
|
||
|
command.append(" --primary");
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
command.append(" --off");
|
||
13 years ago
|
}
|
||
|
}
|
||
|
else {
|
||
13 years ago
|
printf("[WARNING] Unable to find configuration for monitor %d; settings may not be correctly applied...\n\r", i); fflush(stdout);
|
||
13 years ago
|
}
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
|
||
13 years ago
|
TQString xrandr_command_output = exec(command.ascii());
|
||
|
xrandr_command_output = xrandr_command_output.stripWhiteSpace();
|
||
13 years ago
|
if (test) {
|
||
|
if (xrandr_command_output != "") {
|
||
12 years ago
|
applyDisplayConfiguration(oldconfig, FALSE, kde_confdir);
|
||
13 years ago
|
accepted = false;
|
||
|
destroyScreenInformationObject(oldconfig);
|
||
|
KMessageBox::sorry(0, xrandr_command_output, i18n("XRandR encountered a problem"));
|
||
|
return accepted;
|
||
|
}
|
||
13 years ago
|
}
|
||
13 years ago
|
#else
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
|
// Turn off all displays
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
|
||
|
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
|
randr_screen_info->cur_output = randr_screen_info->outputs[i];
|
||
|
randr_screen_info->cur_output->auto_set = 0;
|
||
|
randr_screen_info->cur_output->off_set = 1;
|
||
|
output_off (randr_screen_info, randr_screen_info->cur_output);
|
||
|
j=main_low_apply(randr_screen_info);
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
|
// Turn on the primary display
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
|
||
|
if (screendata->is_primary == true) {
|
||
|
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
|
randr_screen_info->cur_output = randr_screen_info->outputs[i];
|
||
|
randr_screen_info->cur_output->auto_set = 1;
|
||
|
randr_screen_info->cur_output->off_set = 0;
|
||
|
output_auto (randr_screen_info, randr_screen_info->cur_output);
|
||
|
j=main_low_apply(randr_screen_info);
|
||
|
}
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
// Handle the remaining displays
|
||
|
randr_screen_info = read_screen_info(randr_display);
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
|
||
|
// Activate or deactivate the screens as necessary
|
||
|
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
|
randr_screen_info->cur_output = randr_screen_info->outputs[i];
|
||
|
if (screendata->is_primary == false) {
|
||
|
if (screendata->is_primary || screendata->is_extended) {
|
||
|
randr_screen_info->cur_output->auto_set = 1;
|
||
|
randr_screen_info->cur_output->off_set = 0;
|
||
|
output_auto (randr_screen_info, randr_screen_info->cur_output);
|
||
|
j=main_low_apply(randr_screen_info);
|
||
|
}
|
||
|
else {
|
||
|
randr_screen_info->cur_output->auto_set = 0;
|
||
|
randr_screen_info->cur_output->off_set = 1;
|
||
|
output_off (randr_screen_info, randr_screen_info->cur_output);
|
||
|
j=main_low_apply(randr_screen_info);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
|
||
|
if (screendata->is_primary || screendata->is_extended) {
|
||
|
// Set rotation, refresh rate, and size
|
||
13 years ago
|
RandRScreen *cur_screen = new RandRScreen(i);
|
||
|
cur_screen->proposeSize(screendata->current_resolution_index);
|
||
|
cur_screen->proposeRefreshRate(screendata->current_refresh_rate_index);
|
||
|
cur_screen->proposeRotation(getHardwareRotationFlags(screendata));
|
||
|
cur_screen->applyProposed();
|
||
|
delete cur_screen;
|
||
13 years ago
|
|
||
|
// Force data reload
|
||
|
randr_screen_info = read_screen_info(randr_display);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
|
||
|
// Finally, set the screen's position
|
||
|
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
13 years ago
|
if (randr_screen_info->cur_crtc) {
|
||
|
randr_screen_info->cur_crtc->cur_x = screendata->absolute_x_position;
|
||
|
randr_screen_info->cur_crtc->cur_y = screendata->absolute_y_position;
|
||
|
j=main_low_apply(randr_screen_info);
|
||
|
}
|
||
13 years ago
|
}
|
||
|
}
|
||
13 years ago
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
#endif
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
applyDisplayGamma(screenInfoArray);
|
||
|
applyDisplayDPMS(screenInfoArray);
|
||
13 years ago
|
TQString current_icc_profile = getCurrentProfile();
|
||
|
applySystemWideIccConfiguration(kde_confdir);
|
||
|
applyIccConfiguration(current_icc_profile, kde_confdir);
|
||
13 years ago
|
|
||
13 years ago
|
if (test == TRUE) {
|
||
|
int ret = showTestConfigurationDialog();
|
||
|
if (!ret) {
|
||
12 years ago
|
applyDisplayConfiguration(oldconfig, FALSE, kde_confdir);
|
||
13 years ago
|
accepted = false;
|
||
|
}
|
||
|
destroyScreenInformationObject(oldconfig);
|
||
|
}
|
||
|
|
||
|
return accepted;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQPtrList<SingleScreenData> KRandrSimpleAPI::copyScreenInformationObject(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
|
SingleScreenData *origscreendata;
|
||
|
SingleScreenData *copyscreendata;
|
||
|
TQPtrList<SingleScreenData> retArray;
|
||
|
for ( origscreendata = screenInfoArray.first(); origscreendata; origscreendata = screenInfoArray.next() ) {
|
||
|
copyscreendata = new SingleScreenData;
|
||
|
*copyscreendata = *origscreendata;
|
||
|
retArray.append(copyscreendata);
|
||
|
}
|
||
|
return retArray;
|
||
|
}
|
||
|
|
||
13 years ago
|
void KRandrSimpleAPI::destroyScreenInformationObject(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
|
SingleScreenData *screendata;
|
||
|
for ( screendata = screenInfoArray.first(); screendata; screendata = screenInfoArray.next() ) {
|
||
|
screenInfoArray.remove(screendata);
|
||
|
delete screendata;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KRandrSimpleAPI::ensureMonitorDataConsistency(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
|
int i;
|
||
|
SingleScreenData *screendata;
|
||
|
|
||
|
int numberOfScreens = screenInfoArray.count();
|
||
|
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (!screendata->screen_connected) {
|
||
|
screendata->is_primary = false;
|
||
|
screendata->is_extended = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool has_primary_monitor = false;
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
12 years ago
|
if (screendata->is_primary) {
|
||
13 years ago
|
has_primary_monitor = true;
|
||
12 years ago
|
}
|
||
13 years ago
|
}
|
||
|
if (!has_primary_monitor) {
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (!has_primary_monitor) {
|
||
13 years ago
|
if (screendata->screen_connected && screendata->is_extended) {
|
||
13 years ago
|
screendata->is_primary = true;
|
||
|
screendata->is_extended = true;
|
||
|
has_primary_monitor = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!has_primary_monitor) {
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (!has_primary_monitor) {
|
||
|
if (screendata->screen_connected) {
|
||
|
screendata->is_primary = true;
|
||
|
screendata->is_extended = true;
|
||
|
has_primary_monitor = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
bool found_first_primary_monitor = false;
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (screendata->is_primary) {
|
||
|
if (!found_first_primary_monitor) {
|
||
|
found_first_primary_monitor = true;
|
||
|
}
|
||
|
else {
|
||
|
screendata->is_primary = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (screendata->is_primary) {
|
||
|
screendata->is_extended = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
TQString resolutionstring = screendata->resolutions[screendata->current_resolution_index];
|
||
|
int separator_pos = resolutionstring.find(" x ");
|
||
|
TQString x_res_string = resolutionstring.left(separator_pos);
|
||
|
TQString y_res_string = resolutionstring.right(resolutionstring.length()-separator_pos-3);
|
||
|
screendata->current_x_pixel_count = x_res_string.toInt();
|
||
|
screendata->current_y_pixel_count = y_res_string.toInt();
|
||
|
screendata->current_orientation_mask = getHardwareRotationFlags(screendata);
|
||
|
}
|
||
13 years ago
|
|
||
|
// Each screen's absolute position is given relative to the primary monitor
|
||
|
// Fix up the absolute positions
|
||
|
int primary_offset_x = 0;
|
||
|
int primary_offset_y = 0;
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (screendata->is_primary) {
|
||
|
primary_offset_x = screendata->absolute_x_position;
|
||
|
primary_offset_y = screendata->absolute_y_position;
|
||
|
primary_offset_x = primary_offset_x * (-1);
|
||
|
primary_offset_y = primary_offset_y * (-1);
|
||
|
}
|
||
|
}
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
screendata->absolute_x_position = screendata->absolute_x_position + primary_offset_x;
|
||
|
screendata->absolute_y_position = screendata->absolute_y_position + primary_offset_y;
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
TQPoint KRandrSimpleAPI::primaryScreenOffsetFromTLC(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
|
int i;
|
||
|
SingleScreenData *screendata;
|
||
|
int numberOfScreens = screenInfoArray.count();
|
||
|
|
||
|
int primary_offset_x = 0;
|
||
|
int primary_offset_y = 0;
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
if (screendata->absolute_x_position < primary_offset_x) {
|
||
|
primary_offset_x = screendata->absolute_x_position;
|
||
|
}
|
||
|
if (screendata->absolute_y_position < primary_offset_y) {
|
||
|
primary_offset_y = screendata->absolute_y_position;
|
||
|
}
|
||
|
}
|
||
|
primary_offset_x = primary_offset_x * (-1);
|
||
|
primary_offset_y = primary_offset_y * (-1);
|
||
|
|
||
|
return TQPoint(primary_offset_x, primary_offset_y);
|
||
|
}
|
||
|
|
||
12 years ago
|
HotPlugRulesList KRandrSimpleAPI::getHotplugRules(TQString kde_confdir) {
|
||
|
int i;
|
||
|
TQString filename;
|
||
|
HotPlugRulesList ret;
|
||
|
|
||
|
filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
|
||
|
TQStringList grouplist = display_config->groupList();
|
||
|
for ( TQStringList::Iterator it = grouplist.begin(); it != grouplist.end(); ++it ) {
|
||
|
if (!(*it).startsWith("Hotplug-Rule")) {
|
||
|
continue;
|
||
|
}
|
||
|
HotPlugRule rule;
|
||
|
display_config->setGroup(*it);
|
||
|
rule.outputs = display_config->readListEntry("Outputs");
|
||
|
rule.states = display_config->readIntListEntry("States");
|
||
|
rule.profileName = display_config->readEntry("Profile");
|
||
|
ret.append(rule);
|
||
|
}
|
||
|
delete display_config;
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
void KRandrSimpleAPI::saveHotplugRules(HotPlugRulesList rules, TQString kde_confdir) {
|
||
|
int i;
|
||
|
TQString filename;
|
||
|
|
||
|
filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
TQStringList grouplist = display_config->groupList();
|
||
|
for ( TQStringList::Iterator it = grouplist.begin(); it != grouplist.end(); ++it ) {
|
||
|
if (!(*it).startsWith("Hotplug-Rule")) {
|
||
|
continue;
|
||
|
}
|
||
|
display_config->deleteGroup(*it, true, false);
|
||
|
}
|
||
|
HotPlugRulesList::Iterator it;
|
||
|
i=0;
|
||
|
for (it=rules.begin(); it != rules.end(); ++it) {
|
||
|
display_config->setGroup(TQString("Hotplug-Rule%1").arg(i));
|
||
|
display_config->writeEntry("Outputs", (*it).outputs);
|
||
|
display_config->writeEntry("States", (*it).states);
|
||
|
display_config->writeEntry("Profile", (*it).profileName);
|
||
|
i++;
|
||
|
}
|
||
|
display_config->sync();
|
||
|
delete display_config;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool KRandrSimpleAPI::getDisplayConfigurationEnabled(TQString kde_confdir) {
|
||
|
TQString filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
display_config->setGroup("General");
|
||
|
bool enabled = display_config->readBoolEntry("EnableDisplayControl", false);
|
||
|
delete display_config;
|
||
|
|
||
|
return enabled;
|
||
|
}
|
||
|
|
||
|
bool KRandrSimpleAPI::getDisplayConfigurationStartupAutoApplyEnabled(TQString kde_confdir) {
|
||
|
TQString filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
display_config->setGroup("General");
|
||
|
bool applyonstart = display_config->readBoolEntry("ApplySettingsOnStart", false);
|
||
|
delete display_config;
|
||
|
|
||
|
return applyonstart;
|
||
|
}
|
||
|
|
||
|
TQString KRandrSimpleAPI::getDisplayConfigurationStartupAutoApplyName(TQString kde_confdir) {
|
||
|
TQString filename = "displayglobals";
|
||
|
filename.prepend(kde_confdir.append("/"));
|
||
|
KSimpleConfig* display_config = new KSimpleConfig( filename );
|
||
|
display_config->setGroup("General");
|
||
|
TQString profilename = display_config->readEntry("StartupProfileName", "");
|
||
|
delete display_config;
|
||
|
|
||
|
return profilename;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KRandrSimpleAPI::applyHotplugRules(TQString kde_confdir) {
|
||
12 years ago
|
bool enabled = getDisplayConfigurationEnabled(kde_confdir);
|
||
|
if (!enabled) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
HotPlugRulesList rules = getHotplugRules(kde_confdir);
|
||
|
TQPtrList<SingleScreenData> screenInfoArray = readCurrentDisplayConfiguration();
|
||
|
|
||
|
int i;
|
||
|
int j;
|
||
|
TQString bestRule;
|
||
|
int bestRuleMatchCount = 0;
|
||
|
SingleScreenData *screendata = NULL;
|
||
|
HotPlugRulesList::Iterator it;
|
||
|
for (it=rules.begin(); it != rules.end(); ++it) {
|
||
|
// Compare each rule against the current display configuration
|
||
|
// It an output matches the state given in the rule, increment matchCount
|
||
|
HotPlugRule rule = *it;
|
||
|
int matchCount = 0;
|
||
|
int numberOfScreens = screenInfoArray.count();
|
||
|
for (i=0;i<numberOfScreens;i++) {
|
||
|
screendata = screenInfoArray.at(i);
|
||
|
for (j=0; j<(*it).outputs.count(); j++) {
|
||
|
if ((*it).outputs[j] != screendata->screenUniqueName) {
|
||
|
continue;
|
||
|
}
|
||
|
if ((*it).states[j] == HotPlugRule::Connected) {
|
||
|
if (screendata->screen_connected) {
|
||
|
matchCount++;
|
||
|
}
|
||
|
}
|
||
|
else if ((*it).states[j] == HotPlugRule::Disconnected) {
|
||
|
if (!screendata->screen_connected) {
|
||
|
matchCount++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (matchCount > bestRuleMatchCount) {
|
||
|
bestRuleMatchCount = matchCount;
|
||
|
bestRule = rule.profileName;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
destroyScreenInformationObject(screenInfoArray);
|
||
|
|
||
|
if (bestRuleMatchCount > 0) {
|
||
|
// At least one rule matched...
|
||
|
// Apply the profile name in bestRule to the display hardware
|
||
|
applyDisplayConfiguration(bestRule, kde_confdir);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KRandrSimpleAPI::applyDisplayGamma(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
13 years ago
|
int i;
|
||
|
Display *randr_display;
|
||
|
XRROutputInfo *output_info;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
XRRCrtcGamma *gamma;
|
||
|
|
||
|
SingleScreenData *screendata;
|
||
|
|
||
|
if (isValid() == true) {
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
13 years ago
|
if (!current_crtc) {
|
||
|
continue;
|
||
|
}
|
||
13 years ago
|
// vvvvvvvvv This chunk of code is borrowed from xrandr vvvvvvvvvv
|
||
|
int size = XRRGetCrtcGammaSize(randr_display, current_crtc->id);
|
||
|
if (!size) {
|
||
|
continue;
|
||
|
}
|
||
|
gamma = XRRAllocGamma(size);
|
||
|
if (!gamma) {
|
||
|
continue;
|
||
|
}
|
||
|
for (i = 0; i < size; i++) {
|
||
|
if (screendata->gamma_red == 1.0)
|
||
|
gamma->red[i] = i << 8;
|
||
|
else
|
||
|
gamma->red[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_red) * (double)(size-1)*256);
|
||
|
|
||
|
if (screendata->gamma_green == 1.0)
|
||
|
gamma->green[i] = i << 8;
|
||
|
else
|
||
|
gamma->green[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_green) * (double)(size-1)*256);
|
||
|
|
||
|
if (screendata->gamma_blue == 1.0)
|
||
|
gamma->blue[i] = i << 8;
|
||
|
else
|
||
|
gamma->blue[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_blue) * (double)(size-1)*256);
|
||
|
}
|
||
|
XRRSetCrtcGamma(randr_display, current_crtc->id, gamma);
|
||
|
free(gamma);
|
||
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||
|
}
|
||
|
freeScreenInfoStructure(randr_screen_info);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void KRandrSimpleAPI::applyDisplayDPMS(TQPtrList<SingleScreenData> screenInfoArray) {
|
||
13 years ago
|
int i;
|
||
|
Display *randr_display;
|
||
|
XRROutputInfo *output_info;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
XRRCrtcGamma *gamma;
|
||
|
|
||
|
SingleScreenData *screendata;
|
||
|
|
||
|
if (isValid() == true) {
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
13 years ago
|
for (i = 0; i < screenInfoArray.count(); i++) {
|
||
13 years ago
|
screendata = screenInfoArray.at(i);
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
|
CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
|
if (!current_crtc) {
|
||
|
continue;
|
||
|
}
|
||
|
if (!screendata->has_dpms) {
|
||
|
continue;
|
||
|
}
|
||
|
if (screendata->enable_dpms) {
|
||
|
DPMSSetTimeouts(randr_display, screendata->dpms_standby_delay, screendata->dpms_suspend_delay, screendata->dpms_off_delay);
|
||
|
DPMSEnable(randr_display);
|
||
|
}
|
||
|
else {
|
||
|
DPMSDisable(randr_display);
|
||
|
}
|
||
|
}
|
||
|
freeScreenInfoStructure(randr_screen_info);
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
void KRandrSimpleAPI::freeScreenInfoStructure(ScreenInfo* screen_info) {
|
||
|
int i;
|
||
|
|
||
|
for (i=0; i<screen_info->n_crtc; i++) {
|
||
|
free(screen_info->crtcs[i]);
|
||
|
}
|
||
|
for (i=0; i<screen_info->n_output; i++) {
|
||
|
free(screen_info->outputs[i]);
|
||
|
}
|
||
|
free(screen_info->outputs);
|
||
|
free(screen_info->crtcs);
|
||
|
free(screen_info);
|
||
|
}
|
||
|
|
||
13 years ago
|
TQPtrList<SingleScreenData> KRandrSimpleAPI::readCurrentDisplayConfiguration() {
|
||
|
// Discover display information
|
||
|
int i;
|
||
|
int j;
|
||
|
|
||
|
XRROutputInfo *output_info;
|
||
|
SingleScreenData *screendata;
|
||
|
TQPtrList<SingleScreenData> screenInfoArray;
|
||
|
|
||
|
Display *randr_display;
|
||
|
ScreenInfo *randr_screen_info;
|
||
|
|
||
|
// Clear existing info
|
||
|
destroyScreenInformationObject(screenInfoArray);
|
||
13 years ago
|
|
||
13 years ago
|
int numberOfScreens = 0;
|
||
|
if (isValid() == true) {
|
||
13 years ago
|
randr_display = tqt_xdisplay();
|
||
13 years ago
|
randr_screen_info = read_screen_info(randr_display);
|
||
|
for (i = 0; i < randr_screen_info->n_output; i++) {
|
||
|
output_info = randr_screen_info->outputs[i]->info;
|
||
13 years ago
|
CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc;
|
||
13 years ago
|
|
||
|
// Create new data object
|
||
|
screendata = new SingleScreenData;
|
||
|
screenInfoArray.append(screendata);
|
||
12 years ago
|
screendata->screenUniqueName = TQString(i18n("%1:%2")).arg(":0").arg(capitalizeString(output_info->name)); // [FIXME] How can I get the name of the Xorg graphics driver currently in use?
|
||
13 years ago
|
screendata->screenFriendlyName = TQString(i18n("%1. %2 output on %3")).arg(i+1).arg(capitalizeString(output_info->name)).arg(":0"); // [FIXME] How can I get the name of the Xorg graphics driver currently in use?
|
||
|
screendata->generic_screen_detected = false;
|
||
|
|
||
|
// Attempt to use KMS to find screen EDID and name
|
||
|
TQString edid = getEDIDMonitorName(0, output_info->name); // [FIXME] Don't hardwire to card 0!
|
||
|
if (!edid.isNull()) {
|
||
|
screendata->screenFriendlyName = TQString(i18n("%1. %2 on %3 on card %4")).arg(i+1).arg(edid).arg(capitalizeString(output_info->name)).arg("0"); // [FIXME] How can I get the name of the Xorg graphics driver currently in use?
|
||
|
}
|
||
|
|
||
|
// Get resolutions
|
||
13 years ago
|
bool screen_active;
|
||
|
RandRScreen *cur_screen = 0;
|
||
|
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
|
||
|
// Output DISCONNECTED
|
||
|
screen_active = false;
|
||
|
}
|
||
|
else {
|
||
|
if (randr_screen_info->outputs[i]->cur_crtc) {
|
||
|
// Output CONNECTED and ON
|
||
|
screen_active = true;
|
||
|
cur_screen = new RandRScreen(i);
|
||
|
}
|
||
|
else {
|
||
|
// Output CONNECTED and OFF
|
||
|
screen_active = false;
|
||
|
cur_screen = new RandRScreen(i);
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
// Get DPMS information
|
||
13 years ago
|
screendata->has_dpms = 1; // [FIXME] Master Xorg check for global DPMS support should go here if possible
|
||
13 years ago
|
if (screendata->has_dpms) {
|
||
|
CARD16 dpms_standby_delay;
|
||
|
CARD16 dpms_suspend_delay;
|
||
|
CARD16 dpms_off_delay;
|
||
|
screendata->has_dpms = DPMSGetTimeouts(randr_display, &dpms_standby_delay, &dpms_suspend_delay, &dpms_off_delay);
|
||
|
screendata->dpms_standby_delay = dpms_standby_delay;
|
||
|
screendata->dpms_suspend_delay = dpms_suspend_delay;
|
||
|
screendata->dpms_off_delay = dpms_off_delay;
|
||
|
if (screendata->has_dpms) {
|
||
|
CARD16 power_level;
|
||
|
BOOL enable_dpms;
|
||
|
screendata->has_dpms = DPMSInfo(randr_display, &power_level, &enable_dpms);
|
||
|
screendata->enable_dpms = enable_dpms;
|
||
|
}
|
||
|
}
|
||
|
if (!screendata->has_dpms) {
|
||
|
screendata->enable_dpms = false;
|
||
|
screendata->dpms_standby_delay = 0;
|
||
|
screendata->dpms_suspend_delay = 0;
|
||
|
screendata->dpms_off_delay = 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
if (cur_screen) {
|
||
|
screendata->screen_connected = true;
|
||
|
for (int j = 0; j < cur_screen->numSizes(); j++) {
|
||
13 years ago
|
screendata->resolutions.append(i18n("%1 x %2").arg(cur_screen->pixelSize(j).width()).arg(cur_screen->pixelSize(j).height()));
|
||
13 years ago
|
}
|
||
13 years ago
|
screendata->current_resolution_index = 0;
|
||
|
if (current_crtc) {
|
||
13 years ago
|
screendata->current_resolution_index = screendata->resolutions.findIndex(i18n("%1 x %2").arg(current_crtc->info->width).arg(current_crtc->info->height));
|
||
13 years ago
|
}
|
||
|
if (screendata->current_resolution_index < 0) {
|
||
|
screendata->current_resolution_index = cur_screen->proposedSize();
|
||
|
}
|
||
13 years ago
|
|
||
13 years ago
|
// Get refresh rates
|
||
|
TQStringList rr = cur_screen->refreshRates(screendata->current_resolution_index);
|
||
|
for (TQStringList::Iterator it = rr.begin(); it != rr.end(); ++it) {
|
||
|
screendata->refresh_rates.append(*it);
|
||
|
}
|
||
|
screendata->current_refresh_rate_index = cur_screen->proposedRefreshRate();
|
||
13 years ago
|
|
||
13 years ago
|
// Get color depths
|
||
|
// [FIXME]
|
||
|
screendata->color_depths.append(i18n("Default"));
|
||
|
screendata->current_color_depth_index = 0;
|
||
13 years ago
|
|
||
13 years ago
|
// Get orientation flags
|
||
|
// RandRScreen::Rotate0
|
||
|
// RandRScreen::Rotate90
|
||
|
// RandRScreen::Rotate180
|
||
|
// RandRScreen::Rotate270
|
||
|
// RandRScreen::ReflectX
|
||
|
// RandRScreen::ReflectY
|
||
13 years ago
|
|
||
12 years ago
|
screendata->rotations.append(i18n(ROTATION_0_DEGREES_STRING));
|
||
|
screendata->rotations.append(i18n(ROTATION_90_DEGREES_STRING));
|
||
|
screendata->rotations.append(i18n(ROTATION_180_DEGREES_STRING));
|
||
|
screendata->rotations.append(i18n(ROTATION_270_DEGREES_STRING));
|
||
13 years ago
|
screendata->supports_transformations = (cur_screen->rotations() != RandRScreen::Rotate0);
|
||
12 years ago
|
if (screendata->supports_transformations) {
|
||
|
screendata->current_orientation_mask = cur_screen->proposedRotation();
|
||
|
switch (screendata->current_orientation_mask & RandRScreen::RotateMask) {
|
||
|
case RandRScreen::Rotate0:
|
||
|
screendata->current_rotation_index = 0;
|
||
|
break;
|
||
|
case RandRScreen::Rotate90:
|
||
|
screendata->current_rotation_index = 1;
|
||
|
break;
|
||
|
case RandRScreen::Rotate180:
|
||
|
screendata->current_rotation_index = 2;
|
||
|
break;
|
||
|
case RandRScreen::Rotate270:
|
||
|
screendata->current_rotation_index = 3;
|
||
|
break;
|
||
|
default:
|
||
|
// Shouldn't hit this one
|
||
|
Q_ASSERT(screendata->current_orientation_mask & RandRScreen::RotateMask);
|
||
|
screendata->current_rotation_index = 0;
|
||
|
break;
|
||
|
}
|
||
|
screendata->has_x_flip = (screendata->current_orientation_mask & RandRScreen::ReflectX);
|
||
|
screendata->has_y_flip = (screendata->current_orientation_mask & RandRScreen::ReflectY);
|
||
|
}
|
||
|
else {
|
||
|
screendata->has_x_flip = false;
|
||
|
screendata->has_y_flip = false;
|
||
|
screendata->current_rotation_index = 0;
|
||
|
}
|
||
13 years ago
|
|
||
13 years ago
|
// Determine if this display is primary and/or extended
|
||
13 years ago
|
RROutput primaryoutput = XRRGetOutputPrimary(tqt_xdisplay(), DefaultRootWindow(tqt_xdisplay()));
|
||
12 years ago
|
if (primaryoutput == randr_screen_info->outputs[i]->id) {
|
||
13 years ago
|
screendata->is_primary = false;
|
||
12 years ago
|
}
|
||
|
else {
|
||
13 years ago
|
screendata->is_primary = true;
|
||
12 years ago
|
}
|
||
13 years ago
|
screendata->is_extended = screen_active;
|
||
12 years ago
|
if (!screendata->is_extended) {
|
||
13 years ago
|
screendata->is_primary = false;
|
||
12 years ago
|
}
|
||
13 years ago
|
|
||
13 years ago
|
// Get this screen's absolute position
|
||
|
screendata->absolute_x_position = 0;
|
||
|
screendata->absolute_y_position = 0;
|
||
13 years ago
|
if (current_crtc) {
|
||
|
screendata->absolute_x_position = current_crtc->info->x;
|
||
|
screendata->absolute_y_position = current_crtc->info->y;
|
||
|
}
|
||
|
|
||
13 years ago
|
// Get this screen's current resolution
|
||
|
screendata->current_x_pixel_count = cur_screen->pixelSize(screendata->current_resolution_index).width();
|
||
|
screendata->current_y_pixel_count = cur_screen->pixelSize(screendata->current_resolution_index).height();
|
||
13 years ago
|
|
||
13 years ago
|
// Get this screen's current gamma values
|
||
|
// [FIXME]
|
||
|
// This attempts to guess a gamma value based on the LUT settings at 50%
|
||
|
// It may not always be 100% correct, or even anywhere close...
|
||
|
// Essentially it "undoes" the LUT gamma calculation from xrandr
|
||
|
// lut_gamma->green[i] = (pow(i/(size - 1), desired_gamma.green) * (size - 1) * 256);
|
||
|
if (current_crtc) {
|
||
|
//int slot = 127;
|
||
|
int slot = 7;
|
||
|
int size = XRRGetCrtcGammaSize(randr_display, current_crtc->id);
|
||
|
XRRCrtcGamma *gammastruct = XRRGetCrtcGamma (randr_display, current_crtc->id);
|
||
|
screendata->gamma_red = log(gammastruct->red[slot]/((size-1.0)*256.0))/log(slot/(size-1.0));
|
||
|
screendata->gamma_green = log(gammastruct->green[slot]/((size-1.0)*256.0))/log(slot/(size-1.0));
|
||
|
screendata->gamma_blue = log(gammastruct->blue[slot]/((size-1.0)*256.0))/log(slot/(size-1.0));
|
||
|
}
|
||
|
else {
|
||
|
screendata->gamma_red = 2.2;
|
||
|
screendata->gamma_green = 2.2;
|
||
|
screendata->gamma_blue = 2.2;
|
||
|
}
|
||
|
// Round off the gamma to one decimal place
|
||
|
screendata->gamma_red = floorf(screendata->gamma_red * 10 + 0.5) / 10;
|
||
|
screendata->gamma_green = floorf(screendata->gamma_green * 10 + 0.5) / 10;
|
||
|
screendata->gamma_blue = floorf(screendata->gamma_blue * 10 + 0.5) / 10;
|
||
|
|
||
13 years ago
|
delete cur_screen;
|
||
13 years ago
|
}
|
||
|
else {
|
||
|
// Fill in generic data for this disconnected output
|
||
|
screendata->screenFriendlyName = screendata->screenFriendlyName + TQString(" (") + i18n("disconnected") + TQString(")");
|
||
|
screendata->screen_connected = false;
|
||
|
|
||
|
screendata->resolutions = i18n("Default");
|
||
|
screendata->refresh_rates = i18n("Default");
|
||
|
screendata->color_depths = i18n("Default");
|
||
|
screendata->rotations = i18n("N/A");
|
||
13 years ago
|
|
||
13 years ago
|
screendata->current_resolution_index = 0;
|
||
|
screendata->current_refresh_rate_index = 0;
|
||
|
screendata->current_color_depth_index = 0;
|
||
13 years ago
|
|
||
13 years ago
|
screendata->gamma_red = 2.2;
|
||
|
screendata->gamma_green = 2.2;
|
||
|
screendata->gamma_blue = 2.2;
|
||
|
|
||
13 years ago
|
screendata->current_rotation_index = 0;
|
||
|
screendata->current_orientation_mask = 0;
|
||
|
screendata->has_x_flip = false;
|
||
|
screendata->has_y_flip = false;
|
||
|
screendata->supports_transformations = false;
|
||
13 years ago
|
|
||
13 years ago
|
screendata->is_primary = false;
|
||
|
screendata->is_extended = false;
|
||
|
screendata->absolute_x_position = 0;
|
||
|
screendata->absolute_y_position = 0;
|
||
|
screendata->current_x_pixel_count = 640;
|
||
|
screendata->current_y_pixel_count = 480;
|
||
|
}
|
||
|
|
||
|
// Check for more screens...
|
||
|
numberOfScreens++;
|
||
|
}
|
||
13 years ago
|
|
||
|
freeScreenInfoStructure(randr_screen_info);
|
||
13 years ago
|
}
|
||
|
else {
|
||
|
screendata = new SingleScreenData;
|
||
|
screenInfoArray.append(screendata);
|
||
|
|
||
|
// Fill in a bunch of generic data
|
||
|
screendata->screenFriendlyName = i18n("Default output on generic video card");
|
||
|
screendata->generic_screen_detected = true;
|
||
|
screendata->screen_connected = true;
|
||
13 years ago
|
|
||
13 years ago
|
screendata->resolutions = i18n("Default");
|
||
|
screendata->refresh_rates = i18n("Default");
|
||
|
screendata->color_depths = i18n("Default");
|
||
|
screendata->rotations = i18n("N/A");
|
||
13 years ago
|
|
||
13 years ago
|
screendata->current_resolution_index = 0;
|
||
|
screendata->current_refresh_rate_index = 0;
|
||
|
screendata->current_color_depth_index = 0;
|
||
13 years ago
|
|
||
13 years ago
|
screendata->gamma_red = 2.2;
|
||
|
screendata->gamma_green = 2.2;
|
||
|
screendata->gamma_blue = 2.2;
|
||
|
|
||
13 years ago
|
screendata->current_rotation_index = 0;
|
||
|
screendata->current_orientation_mask = 0;
|
||
|
screendata->has_x_flip = false;
|
||
|
screendata->has_y_flip = false;
|
||
|
screendata->supports_transformations = false;
|
||
13 years ago
|
|
||
13 years ago
|
screendata->is_primary = true;
|
||
|
screendata->is_extended = true;
|
||
|
screendata->absolute_x_position = 0;
|
||
|
screendata->absolute_y_position = 0;
|
||
|
screendata->current_x_pixel_count = 640;
|
||
|
screendata->current_y_pixel_count = 480;
|
||
|
|
||
|
numberOfScreens++;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool primary_set = false;
|
||
|
for ( screendata=screenInfoArray.first(); screendata; screendata=screenInfoArray.next() ) {
|
||
|
if (screendata->is_primary) {
|
||
|
primary_set = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// If there is no primary monitor set, xrandr is probably not functioning correctly!
|
||
|
Q_ASSERT(primary_set);
|
||
|
if (!primary_set) {
|
||
|
// [FIXME]
|
||
|
// Set this on the real primary monitor only!
|
||
|
screendata = screenInfoArray.at(0);
|
||
|
screendata->is_primary = true;
|
||
|
}
|
||
13 years ago
|
|
||
|
return screenInfoArray;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRandrSimpleAPI::clearIccConfiguration() {
|
||
15 years ago
|
// Clear ICC settings with XCalib
|
||
15 years ago
|
TQString icc_command;
|
||
15 years ago
|
FILE *pipe_xcalib;
|
||
|
char xcalib_result[2048];
|
||
|
int i;
|
||
|
xcalib_result[0]=0;
|
||
|
|
||
15 years ago
|
icc_command = TQString("xcalib -c");
|
||
15 years ago
|
if ((pipe_xcalib = popen(icc_command.ascii(), "r")) == NULL)
|
||
|
{
|
||
12 years ago
|
printf("Xcalib pipe error [xcalib clear]\n\r");
|
||
15 years ago
|
}
|
||
|
else {
|
||
12 years ago
|
if (fgets(xcalib_result, 2048, pipe_xcalib)) {
|
||
|
pclose(pipe_xcalib);
|
||
|
for (i=1;i<2048;i++) {
|
||
|
if (xcalib_result[i] == 0) {
|
||
|
xcalib_result[i-1]=0;
|
||
|
i=2048;
|
||
|
}
|
||
|
}
|
||
|
if (strlen(xcalib_result) > 2) {
|
||
|
return xcalib_result;
|
||
15 years ago
|
}
|
||
|
}
|
||
12 years ago
|
else {
|
||
12 years ago
|
return "";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
15 years ago
|
ScreenInfo* KRandrSimpleAPI::read_screen_info (Display *display)
|
||
|
{
|
||
15 years ago
|
return internal_read_screen_info(display);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::set_screen_size (ScreenInfo *screen_info)
|
||
|
{
|
||
15 years ago
|
return internal_set_screen_size(screen_info);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KRandrSimpleAPI::output_auto (ScreenInfo *screen_info, OutputInfo *output_info)
|
||
|
{
|
||
15 years ago
|
internal_output_auto (screen_info, output_info);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KRandrSimpleAPI::output_off(ScreenInfo *screen_info, OutputInfo *output)
|
||
|
{
|
||
15 years ago
|
internal_output_off(screen_info, output);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
CrtcInfo* KRandrSimpleAPI::auto_find_crtc (ScreenInfo *screen_info, OutputInfo *output_info)
|
||
15 years ago
|
{
|
||
14 years ago
|
return internal_auto_find_crtc (screen_info, output_info);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
XRRModeInfo *KRandrSimpleAPI::find_mode_by_xid (ScreenInfo *screen_info, RRMode mode_id)
|
||
15 years ago
|
{
|
||
14 years ago
|
return internal_find_mode_by_xid (screen_info, mode_id);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::mode_height (XRRModeInfo *mode_info, Rotation rotation)
|
||
|
{
|
||
15 years ago
|
return internal_mode_height (mode_info, rotation);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::mode_width (XRRModeInfo *mode_info, Rotation rotation)
|
||
|
{
|
||
15 years ago
|
return internal_mode_width (mode_info, rotation);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::get_width_by_output_id (ScreenInfo *screen_info, RROutput output_id)
|
||
|
{
|
||
15 years ago
|
return internal_get_width_by_output_id (screen_info, output_id);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::get_height_by_output_id (ScreenInfo *screen_info, RROutput output_id)
|
||
|
{
|
||
15 years ago
|
return internal_get_height_by_output_id (screen_info, output_id);
|
||
15 years ago
|
}
|
||
|
|
||
|
char *KRandrSimpleAPI::get_output_name (ScreenInfo *screen_info, RROutput id)
|
||
|
{
|
||
15 years ago
|
return internal_get_output_name (screen_info, id);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
Status KRandrSimpleAPI::crtc_apply (CrtcInfo *crtc_info)
|
||
15 years ago
|
{
|
||
15 years ago
|
return internal_crtc_apply (crtc_info);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
Status KRandrSimpleAPI::crtc_disable (CrtcInfo *crtc)
|
||
15 years ago
|
{
|
||
15 years ago
|
return internal_crtc_disable (crtc);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KRandrSimpleAPI::main_low_apply (ScreenInfo *screen_info)
|
||
|
{
|
||
15 years ago
|
return internal_main_low_apply (screen_info);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void KRandrSimpleAPI::set_primary_output (ScreenInfo *screen_info, RROutput output_id)
|
||
|
{
|
||
|
internal_output_set_primary(screen_info, output_id);
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KRandrSimpleAPI::kRandrHasRandr(void)
|
||
|
{
|
||
|
return isValid();
|
||
|
}
|
||
|
|
||
|
const char *KRandrSimpleAPI::kRandrVersion(void)
|
||
|
{
|
||
|
return "0.9.5";
|
||
|
}
|
||
|
|
||
|
const char *KRandrSimpleAPI::kRandrCopyright(void)
|
||
|
{
|
||
|
return "LibKRandr 0.9.5 (C)2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>. U.S.A.";
|
||
|
}
|
||
|
|
||
|
/* * * * * *
|
||
|
|
||
|
Under this line (------) there's only a C wrapper for the KRandrSimpleAPI class
|
||
|
|
||
|
* * * * * */
|
||
|
const char *kRandrVersion(void)
|
||
|
{
|
||
|
return KRandrSimpleAPI::kRandrVersion();
|
||
|
}
|
||
|
|
||
|
const char *kRandrCopyright(void)
|
||
|
{
|
||
|
return KRandrSimpleAPI::kRandrCopyright();
|
||
|
}
|
||
|
|