TDE base libraries and programs
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.

displayconfig.cpp 72KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  1. /**
  2. * displayconfig.cpp
  3. *
  4. * Copyright (c) 2009-2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #include <tqcheckbox.h>
  21. #include <tqlabel.h>
  22. #include <tqlayout.h>
  23. #include <tqlineedit.h>
  24. #include <tqpushbutton.h>
  25. #include <tqtabwidget.h>
  26. #include <tqtimer.h>
  27. #include <dcopclient.h>
  28. #include <tdeaboutdata.h>
  29. #include <tdeapplication.h>
  30. #include <tdeconfig.h>
  31. #include <kcombobox.h>
  32. #include <kdebug.h>
  33. #include <kdialog.h>
  34. #include <tdeglobal.h>
  35. #include <tdelistview.h>
  36. #include <tdelocale.h>
  37. #include <tdemessagebox.h>
  38. #include <tdepopupmenu.h>
  39. #include <kinputdialog.h>
  40. #include <kurlrequester.h>
  41. #include <tdecmoduleloader.h>
  42. #include <kgenericfactory.h>
  43. #include <kstandarddirs.h>
  44. #include <unistd.h>
  45. #include <ksimpleconfig.h>
  46. #include <string>
  47. #include <stdio.h>
  48. #include <tqstring.h>
  49. #include <math.h>
  50. #define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
  51. #include "displayconfig.h"
  52. using namespace std;
  53. /**** DLL Interface ****/
  54. typedef KGenericFactory<KDisplayConfig, TQWidget> KDisplayCFactory;
  55. K_EXPORT_COMPONENT_FACTORY( kcm_displayconfig, KDisplayCFactory("kcmdisplayconfig") )
  56. KSimpleConfig *systemconfig;
  57. TQPoint moveTQRectOutsideTQRect(TQRect base, TQRect movable, int fallback_level = 0) {
  58. TQPoint final_result;
  59. double base_center_x = base.x() + (base.width()/2);
  60. double base_center_y = base.y() + (base.height()/2);
  61. double movable_center_x = movable.x() + (movable.width()/2);
  62. double movable_center_y = movable.y() + (movable.height()/2);
  63. double max_x_movement = (base.width()/2) + (movable.width()/2);
  64. double max_y_movement = (base.height()/2) + (movable.height()/2);
  65. double x_diff = abs(base_center_x-movable_center_x);
  66. double y_diff = abs(base_center_y-movable_center_y);
  67. int invert_movement;
  68. // Calculate the angles of the four corners of the base rectangle
  69. double angle_1 = atan2((base.height()/2), (base.width()/2));
  70. double angle_2 = atan2((base.height()/2), (base.width()/2)*(-1));
  71. double angle_3 = atan2((base.height()/2)*(-1), (base.width()/2)*(-1));
  72. double angle_4 = atan2((base.height()/2)*(-1), (base.width()/2));
  73. // Calculate the angle that the movable rectangle center is on
  74. double movable_angle = atan2(base_center_y-movable_center_y, movable_center_x-base_center_x);
  75. // Fix up coordinates
  76. if (angle_1 < 0) angle_1 = angle_1 + (2*PI);
  77. if (angle_2 < 0) angle_2 = angle_2 + (2*PI);
  78. if (angle_3 < 0) angle_3 = angle_3 + (2*PI);
  79. if (angle_4 < 0) angle_4 = angle_4 + (2*PI);
  80. if (movable_angle < 0) movable_angle = movable_angle + (2*PI);
  81. // Now calculate quadrant
  82. int quadrant;
  83. if ((movable_angle < angle_2) && (movable_angle >= angle_1)) {
  84. quadrant = 2;
  85. }
  86. else if ((movable_angle < angle_3) && (movable_angle >= angle_2)) {
  87. quadrant = 3;
  88. }
  89. else if ((movable_angle < angle_4) && (movable_angle >= angle_3)) {
  90. quadrant = 4;
  91. }
  92. else {
  93. quadrant = 1;
  94. }
  95. if (fallback_level == 0) {
  96. if ((quadrant == 2) || (quadrant == 4)) {
  97. // Move it in the Y direction
  98. if (movable_center_y < base_center_y)
  99. invert_movement = -1;
  100. else
  101. invert_movement = 1;
  102. final_result = TQPoint(0, (max_y_movement-y_diff)*invert_movement);
  103. }
  104. else {
  105. // Move it in the X direction
  106. if (movable_center_x < base_center_x)
  107. invert_movement = -1;
  108. else
  109. invert_movement = 1;
  110. final_result = TQPoint((max_x_movement-x_diff)*invert_movement, 0);
  111. }
  112. }
  113. if (fallback_level == 1) {
  114. if ((quadrant == 1) || (quadrant == 3)) {
  115. // Move it in the Y direction
  116. if (movable_center_y < base_center_y)
  117. invert_movement = -1;
  118. else
  119. invert_movement = 1;
  120. final_result = TQPoint(0, (max_y_movement-y_diff)*invert_movement);
  121. }
  122. else {
  123. // Move it in the X direction
  124. if (movable_center_x < base_center_x)
  125. invert_movement = -1;
  126. else
  127. invert_movement = 1;
  128. final_result = TQPoint((max_x_movement-x_diff)*invert_movement, 0);
  129. }
  130. }
  131. if (fallback_level == 2) {
  132. // Ooh, nasty, I need to move the rectangle the other (suboptimal) direction
  133. if ((quadrant == 2) || (quadrant == 4)) {
  134. // Move it in the Y direction
  135. if (movable_center_y >= base_center_y)
  136. invert_movement = -1;
  137. else
  138. invert_movement = 1;
  139. final_result = TQPoint(0, (max_y_movement+y_diff)*invert_movement);
  140. }
  141. else {
  142. // Move it in the X direction
  143. if (movable_center_x >= base_center_x)
  144. invert_movement = -1;
  145. else
  146. invert_movement = 1;
  147. final_result = TQPoint((max_x_movement+x_diff)*invert_movement, 0);
  148. }
  149. }
  150. if (fallback_level == 3) {
  151. // Ooh, nasty, I need to move the rectangle the other (suboptimal) direction
  152. if ((quadrant == 1) || (quadrant == 3)) {
  153. // Move it in the Y direction
  154. if (movable_center_y >= base_center_y)
  155. invert_movement = -1;
  156. else
  157. invert_movement = 1;
  158. final_result = TQPoint(0, (max_y_movement+y_diff)*invert_movement);
  159. }
  160. else {
  161. // Move it in the X direction
  162. if (movable_center_x >= base_center_x)
  163. invert_movement = -1;
  164. else
  165. invert_movement = 1;
  166. final_result = TQPoint((max_x_movement+x_diff)*invert_movement, 0);
  167. }
  168. }
  169. // Check for intersection
  170. TQRect test_rect = movable;
  171. test_rect.moveBy(final_result.x(), final_result.y());
  172. if (test_rect.intersects(base)) {
  173. if (final_result.x() > 0)
  174. final_result.setX(final_result.x()+1);
  175. if (final_result.x() < 0)
  176. final_result.setX(final_result.x()-1);
  177. if (final_result.y() > 0)
  178. final_result.setY(final_result.y()+1);
  179. if (final_result.y() < 0)
  180. final_result.setY(final_result.y()-1);
  181. }
  182. return final_result;
  183. }
  184. TQPoint moveTQRectSoThatItTouchesTQRect(TQRect base, TQRect movable, int fallback_level = 0) {
  185. TQPoint final_result;
  186. double base_center_x = base.x() + (base.width()/2);
  187. double base_center_y = base.y() + (base.height()/2);
  188. double movable_center_x = movable.x() + (movable.width()/2);
  189. double movable_center_y = movable.y() + (movable.height()/2);
  190. double max_x_movement = (base.width()/2) + (movable.width()/2);
  191. double max_y_movement = (base.height()/2) + (movable.height()/2);
  192. double x_diff = abs(base_center_x-movable_center_x);
  193. double y_diff = abs(base_center_y-movable_center_y);
  194. int invert_movement;
  195. // Calculate the angles of the four corners of the base rectangle
  196. double angle_1 = atan2((base.height()/2), (base.width()/2));
  197. double angle_2 = atan2((base.height()/2), (base.width()/2)*(-1));
  198. double angle_3 = atan2((base.height()/2)*(-1), (base.width()/2)*(-1));
  199. double angle_4 = atan2((base.height()/2)*(-1), (base.width()/2));
  200. // Calculate the angle that the movable rectangle center is on
  201. double movable_angle = atan2(base_center_y-movable_center_y, movable_center_x-base_center_x);
  202. // Fix up coordinates
  203. if (angle_1 < 0) angle_1 = angle_1 + (2*PI);
  204. if (angle_2 < 0) angle_2 = angle_2 + (2*PI);
  205. if (angle_3 < 0) angle_3 = angle_3 + (2*PI);
  206. if (angle_4 < 0) angle_4 = angle_4 + (2*PI);
  207. if (movable_angle < 0) movable_angle = movable_angle + (2*PI);
  208. // Now calculate quadrant
  209. int quadrant;
  210. if ((movable_angle < angle_2) && (movable_angle >= angle_1)) {
  211. quadrant = 2;
  212. }
  213. else if ((movable_angle < angle_3) && (movable_angle >= angle_2)) {
  214. quadrant = 3;
  215. }
  216. else if ((movable_angle < angle_4) && (movable_angle >= angle_3)) {
  217. quadrant = 4;
  218. }
  219. else {
  220. quadrant = 1;
  221. }
  222. if (fallback_level == 0) {
  223. if ((quadrant == 2) || (quadrant == 4)) {
  224. // Move it in the Y direction
  225. if (movable_center_y < base_center_y)
  226. invert_movement = -1;
  227. else
  228. invert_movement = 1;
  229. final_result = TQPoint(0, (max_y_movement-y_diff)*invert_movement);
  230. }
  231. else {
  232. // Move it in the X direction
  233. if (movable_center_x < base_center_x)
  234. invert_movement = -1;
  235. else
  236. invert_movement = 1;
  237. final_result = TQPoint((max_x_movement-x_diff)*invert_movement, 0);
  238. }
  239. }
  240. // Check for intersection
  241. TQRect test_rect = movable;
  242. test_rect.moveBy(final_result.x(), final_result.y());
  243. if (test_rect.intersects(base)) {
  244. if (final_result.x() > 0)
  245. final_result.setX(final_result.x()-1);
  246. if (final_result.x() < 0)
  247. final_result.setX(final_result.x()+1);
  248. if (final_result.y() > 0)
  249. final_result.setY(final_result.y()-1);
  250. if (final_result.y() < 0)
  251. final_result.setY(final_result.y()+1);
  252. }
  253. return final_result;
  254. }
  255. TQPoint moveTQRectOutsideMonitorRegion(TQRect rect, MonitorRegion region) {
  256. // This is a fun little class (not!)
  257. // It needs to move the TQRect so that it does not overlap any rectangles in the region
  258. long rect_center_x = rect.x() + (rect.width()/2);
  259. long rect_center_y = rect.y() + (rect.height()/2);
  260. // First, see if the rectangle actually overlaps the region
  261. if (!region.contains(rect))
  262. return TQPoint(0,0);
  263. // Then, break the region into the series of source rectangles
  264. TQMemArray<TQRect> rectangles = region.rects();
  265. // Next, find which rectangle is closest to the center of the TQRect
  266. int closest = 0;
  267. long distance = 16384*16384;
  268. int fallback_mode = 0;
  269. long test_distance;
  270. long test_center_x;
  271. long test_center_y;
  272. for ( unsigned int i = 0; i < rectangles.size(); i++ ) {
  273. test_center_x = rectangles[i].x() + (rectangles[i].width()/2);
  274. test_center_y = rectangles[i].y() + (rectangles[i].height()/2);
  275. test_distance = pow(test_center_x-rect_center_x,2) + pow(test_center_y-rect_center_y,2);
  276. if (test_distance < distance) {
  277. // Make sure this is an outer rectangle; i,e. there is empty space where
  278. // we would want to move the TQRect...
  279. // To do that we will move the TQRect in all four possible directions,
  280. // and see if any put the TQRect in an empty location
  281. // If they do, then this current rectangle is considered usable
  282. // and it is added to the distance checking routine.
  283. TQPoint test_moveby = moveTQRectOutsideTQRect(rectangles[i], rect, 0);
  284. TQRect test_rect = rect;
  285. test_rect.moveBy(test_moveby.x(), test_moveby.y());
  286. if (!region.contains(test_rect)) {
  287. closest = i;
  288. distance = test_distance;
  289. fallback_mode = 0;
  290. }
  291. else {
  292. test_moveby = moveTQRectOutsideTQRect(rectangles[i], rect, 1);
  293. test_rect = rect;
  294. test_rect.moveBy(test_moveby.x(), test_moveby.y());
  295. if (!region.contains(test_rect)) {
  296. closest = i;
  297. distance = test_distance;
  298. fallback_mode = 1;
  299. }
  300. else {
  301. test_moveby = moveTQRectOutsideTQRect(rectangles[i], rect, 2);
  302. test_rect = rect;
  303. test_rect.moveBy(test_moveby.x(), test_moveby.y());
  304. if (!region.contains(test_rect)) {
  305. closest = i;
  306. distance = test_distance;
  307. fallback_mode = 2;
  308. }
  309. else {
  310. test_moveby = moveTQRectOutsideTQRect(rectangles[i], rect, 3);
  311. test_rect = rect;
  312. test_rect.moveBy(test_moveby.x(), test_moveby.y());
  313. if (!region.contains(test_rect)) {
  314. closest = i;
  315. distance = test_distance;
  316. fallback_mode = 3;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. // Finally, calculate the required translation to move the TQRect outside the MonitorRegion
  324. // so that it touches the closest line found above
  325. return moveTQRectOutsideTQRect(rectangles[closest], rect, fallback_mode);
  326. }
  327. TQPoint compressTQRectTouchingMonitorRegion(TQRect rect, MonitorRegion region, TQSize workspace) {
  328. // This is another fun little class (not!)
  329. // It needs to move the TQRect so that it touches the closest outside line of the MonitorRegion
  330. bool should_move;
  331. long rect_center_x = rect.x() + (rect.width()/2);
  332. long rect_center_y = rect.y() + (rect.height()/2);
  333. // First, break the region into the series of source rectangles
  334. TQMemArray<TQRect> rectangles = region.rects();
  335. // Next, find which rectangle is closest to the center of the TQRect
  336. should_move = false;
  337. int closest = 0;
  338. long distance = 16384*16384;
  339. int fallback_mode;
  340. long test_distance;
  341. long test_center_x;
  342. long test_center_y;
  343. for ( unsigned int i = 0; i < rectangles.size(); i++ ) {
  344. test_center_x = rectangles[i].x() + (rectangles[i].width()/2);
  345. test_center_y = rectangles[i].y() + (rectangles[i].height()/2);
  346. test_distance = pow(test_center_x-rect_center_x,2) + pow(test_center_y-rect_center_y,2);
  347. if ( (abs(test_center_x-(workspace.width()/2))<2) && (abs(test_center_y-(workspace.height()/2))<2) ) {
  348. test_distance=0; // Give the primary monitor "gravity" so it can attract all other monitors to itself
  349. }
  350. if (test_distance < distance) {
  351. // Make sure this is an outer rectangle; i,e. there is empty space where
  352. // we would want to move the TQRect...
  353. // To do that we will move the TQRect in all four possible directions,
  354. // and see if any put the TQRect in an empty location
  355. // If they do, then this current rectangle is considered usable
  356. // and it is added to the distance checking routine.
  357. TQPoint test_moveby = moveTQRectSoThatItTouchesTQRect(rectangles[i], rect, 0);
  358. TQRect test_rect = rect;
  359. test_rect.moveBy(test_moveby.x(), test_moveby.y());
  360. if (!region.contains(test_rect)) {
  361. closest = i;
  362. distance = test_distance;
  363. fallback_mode = 0;
  364. should_move = true;
  365. }
  366. }
  367. }
  368. // Finally, calculate the required translation to move the TQRect outside the MonitorRegion
  369. // so that it touches the closest line found above
  370. if (should_move)
  371. return moveTQRectSoThatItTouchesTQRect(rectangles[closest], rect, fallback_mode);
  372. else
  373. return TQPoint(0, 0);
  374. }
  375. void KDisplayConfig::updateDraggableMonitorInformation (int monitor_id) {
  376. updateDraggableMonitorInformationInternal(monitor_id, true);
  377. changed();
  378. }
  379. void KDisplayConfig::updateDraggableMonitorInformationInternal (int monitor_id, bool recurse) {
  380. int i;
  381. int j=0;
  382. DraggableMonitor *primary_monitor = NULL;
  383. DraggableMonitor *moved_monitor = NULL;
  384. SingleScreenData *screendata = NULL;
  385. TQObjectList monitors;
  386. // Find the moved draggable monitor object
  387. monitors = base->monitorPhyArrange->childrenListObject();
  388. if ( monitors.count() ) {
  389. for ( i = 0; i < int(monitors.count()); ++i ) {
  390. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  391. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  392. if (monitor->screen_id == monitor_id) {
  393. moved_monitor = monitor;
  394. screendata = m_screenInfoArray[activeProfileName].at(moved_monitor->screen_id);
  395. }
  396. }
  397. }
  398. }
  399. if (!screendata) {
  400. return;
  401. }
  402. TQString rotationDesired = *screendata->rotations.at(screendata->current_rotation_index);
  403. bool isvisiblyrotated = ((rotationDesired == ROTATION_90_DEGREES_STRING) || (rotationDesired == ROTATION_270_DEGREES_STRING));
  404. if (screendata->is_extended) {
  405. moved_monitor->show();
  406. }
  407. else {
  408. moved_monitor->hide();
  409. }
  410. // Handle resizing
  411. if (isvisiblyrotated) {
  412. moved_monitor->setFixedSize(screendata->current_y_pixel_count*base->monitorPhyArrange->resize_factor, screendata->current_x_pixel_count*base->monitorPhyArrange->resize_factor);
  413. }
  414. else {
  415. moved_monitor->setFixedSize(screendata->current_x_pixel_count*base->monitorPhyArrange->resize_factor, screendata->current_y_pixel_count*base->monitorPhyArrange->resize_factor);
  416. }
  417. // Find the primary monitor
  418. for (i=0;i<numberOfScreens;i++) {
  419. screendata = m_screenInfoArray[activeProfileName].at(i);
  420. if (screendata->is_primary)
  421. j=i;
  422. }
  423. monitors = base->monitorPhyArrange->childrenListObject();
  424. primary_monitor = NULL;
  425. if ( monitors.count() ) {
  426. for ( i = 0; i < int(monitors.count()); ++i ) {
  427. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  428. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  429. if (monitor->screen_id == j) {
  430. monitor->is_primary = true; // Prevent dragging of the primary monitor
  431. primary_monitor = monitor;
  432. }
  433. else {
  434. monitor->is_primary = false;
  435. }
  436. }
  437. }
  438. }
  439. if (primary_monitor) {
  440. if (moved_monitor != primary_monitor) {
  441. // Run layout rules
  442. applyMonitorLayoutRules(moved_monitor);
  443. int toffset_x = moved_monitor->x() - ((base->monitorPhyArrange->width()/2)-(primary_monitor->width()/2));
  444. int toffset_y = moved_monitor->y() - ((base->monitorPhyArrange->height()/2)-(primary_monitor->height()/2));
  445. int offset_x = toffset_x / base->monitorPhyArrange->resize_factor;
  446. int offset_y = toffset_y / base->monitorPhyArrange->resize_factor;
  447. screendata = m_screenInfoArray[activeProfileName].at(monitor_id);
  448. screendata->absolute_x_position = offset_x;
  449. screendata->absolute_y_position = offset_y;
  450. }
  451. else {
  452. // Reset the position of the primary monitor
  453. moveMonitor(primary_monitor, 0, 0);
  454. }
  455. }
  456. else {
  457. printf("[WARNING] Display layout broken...\n"); fflush(stdout);
  458. }
  459. layoutDragDropDisplay();
  460. // // FIXME Yes, this should work. For some reason it creates big problems instead
  461. // // Run layout rules on all monitors
  462. // if (recurse == true) {
  463. // applyMonitorLayoutRules();
  464. // }
  465. }
  466. bool KDisplayConfig::applyMonitorLayoutRules() {
  467. int i;
  468. for (i=0;i<numberOfScreens;i++) {
  469. updateDraggableMonitorInformationInternal(i, false);
  470. }
  471. return false;
  472. }
  473. bool KDisplayConfig::applyMonitorLayoutRules(DraggableMonitor* monitor_to_move) {
  474. int i;
  475. bool monitor_was_moved;
  476. TQObjectList monitors;
  477. // Ensure that the monitors:
  478. // 1) Do NOT overlap
  479. // 2) Touch on at least one side
  480. monitor_was_moved = false;
  481. // Handle 1)
  482. // First, create a region from the monitor rectangles
  483. // The moved monitor cannot exist within that region
  484. MonitorRegion other_monitors;
  485. monitors = base->monitorPhyArrange->childrenListObject();
  486. if ( monitors.count() ) {
  487. for ( i = 0; i < int(monitors.count()); ++i ) {
  488. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  489. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  490. if (monitor != monitor_to_move) {
  491. other_monitors = other_monitors.unite(MonitorRegion(monitor->geometry()));
  492. }
  493. }
  494. }
  495. }
  496. // Now get the required move X/Y direction
  497. TQPoint req_move = moveTQRectOutsideMonitorRegion(monitor_to_move->geometry(), other_monitors);
  498. // And move the monitor
  499. if (!monitor_to_move->isHidden())
  500. monitor_to_move->move(monitor_to_move->x()+req_move.x(), monitor_to_move->y()+req_move.y());
  501. else {
  502. req_move.setX(0);
  503. req_move.setY(0);
  504. monitor_to_move->move(base->monitorPhyArrange->width(), base->monitorPhyArrange->height());
  505. }
  506. if ((req_move.x() != 0) || (req_move.y() != 0))
  507. monitor_was_moved = true;
  508. // Handle 2)
  509. // Now we need to shrink the monitors so that no gaps appear between then
  510. // All shrinking must take place towards the nearest extant monitor edge
  511. // First, determine which rectangles touch the primary monitor, or touch rectangles that then
  512. // in turn touch the primary monitor
  513. // FIXME
  514. // Only run this routine if we don't touch the primary monitor, or touch any rectangles that
  515. // actually do touch the primary monitor (possible through other rectangles, etc.)...
  516. // This would be for efficiency
  517. // FIXME
  518. // if () {
  519. TQPoint req_move2(-1,-1);
  520. while ((req_move2.x() != 0) || (req_move2.y() != 0)) {
  521. // First, create a region from the monitor rectangles
  522. MonitorRegion other_monitors2;
  523. monitors = base->monitorPhyArrange->childrenListObject();
  524. if ( monitors.count() ) {
  525. for ( i = 0; i < int(monitors.count()); ++i ) {
  526. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  527. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  528. if (monitor != monitor_to_move) {
  529. other_monitors2 = other_monitors2.unite(MonitorRegion(monitor->geometry()));
  530. }
  531. }
  532. }
  533. }
  534. // Now get the required move X/Y direction
  535. req_move2 = compressTQRectTouchingMonitorRegion(monitor_to_move->geometry(), other_monitors, base->monitorPhyArrange->size());
  536. // And move the monitor
  537. if (!monitor_to_move->isHidden())
  538. monitor_to_move->move(monitor_to_move->x()+req_move2.x(), monitor_to_move->y()+req_move2.y());
  539. else {
  540. req_move2.setX(0);
  541. req_move2.setY(0);
  542. monitor_to_move->move(base->monitorPhyArrange->width(), base->monitorPhyArrange->height());
  543. }
  544. if ((req_move2.x() != 0) || (req_move2.y() != 0))
  545. monitor_was_moved = true;
  546. }
  547. // }
  548. return monitor_was_moved;
  549. }
  550. void KDisplayConfig::moveMonitor(DraggableMonitor* monitor, int realx, int realy) {
  551. int i;
  552. int j=0;
  553. bool primary_found;
  554. DraggableMonitor *primary_monitor;
  555. SingleScreenData *screendata;
  556. // Find the primary monitor
  557. primary_found = false;
  558. for (i=0;i<numberOfScreens;i++) {
  559. screendata = m_screenInfoArray[activeProfileName].at(i);
  560. if (screendata->is_primary) {
  561. j=i;
  562. primary_found = true;
  563. }
  564. }
  565. TQObjectList monitors = base->monitorPhyArrange->childrenListObject();
  566. primary_monitor = NULL;
  567. if ( monitors.count() ) {
  568. for ( i = 0; i < int(monitors.count()); ++i ) {
  569. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  570. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  571. if (monitor->screen_id == j) {
  572. monitor->is_primary = true; // Prevent dragging of the primary monitor
  573. primary_monitor = monitor;
  574. }
  575. else {
  576. monitor->is_primary = false;
  577. }
  578. }
  579. }
  580. }
  581. if (primary_found && primary_monitor) {
  582. int tx = realx * base->monitorPhyArrange->resize_factor;
  583. int ty = realy * base->monitorPhyArrange->resize_factor;
  584. if (!monitor->isHidden())
  585. monitor->move((base->monitorPhyArrange->width()/2)-(primary_monitor->width()/2)+tx,(base->monitorPhyArrange->height()/2)-(primary_monitor->height()/2)+ty);
  586. else
  587. monitor->move(base->monitorPhyArrange->width(), base->monitorPhyArrange->height());
  588. }
  589. }
  590. // int KDisplayConfig::realResolutionSliderValue() {
  591. // return base->resolutionSlider->maxValue() - base->resolutionSlider->value();
  592. // }
  593. //
  594. // void KDisplayConfig::setRealResolutionSliderValue(int index) {
  595. // base->resolutionSlider->setValue(base->resolutionSlider->maxValue() - index);
  596. // }
  597. TQStringList sortResolutions(TQStringList unsorted) {
  598. int xres;
  599. int largest;
  600. TQStringList sorted;
  601. TQStringList::Iterator it;
  602. TQStringList::Iterator largestit;
  603. while (unsorted.count()) {
  604. largest = -1;
  605. for ( it = unsorted.begin(); it != unsorted.end(); ++it ) {
  606. TQString resolutionstring = *it;
  607. int separator_pos = resolutionstring.find(" x ");
  608. TQString x_res_string = resolutionstring.left(separator_pos);
  609. TQString y_res_string = resolutionstring.right(resolutionstring.length()-separator_pos-3);
  610. xres = x_res_string.toInt();
  611. if (xres > largest) {
  612. largest = xres;
  613. largestit = it;
  614. }
  615. }
  616. sorted.prepend(*largestit);
  617. unsorted.remove(largestit);
  618. }
  619. return sorted;
  620. }
  621. int KDisplayConfig::realResolutionSliderValue() {
  622. unsigned int i;
  623. unsigned int j;
  624. SingleScreenData *screendata;
  625. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  626. TQStringList sortedList = screendata->resolutions;
  627. sortedList = sortResolutions(sortedList);
  628. j=0;
  629. for (i=0; i<screendata->resolutions.count(); i++) {
  630. if ((*sortedList.at(base->resolutionSlider->value())) == (*screendata->resolutions.at(i))) {
  631. j=i;
  632. }
  633. }
  634. return j;
  635. }
  636. void KDisplayConfig::setRealResolutionSliderValue(int index) {
  637. unsigned int i;
  638. unsigned int j;
  639. SingleScreenData *screendata;
  640. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  641. TQStringList sortedList = screendata->resolutions;
  642. sortedList = sortResolutions(sortedList);
  643. j=0;
  644. for (i=0; i<screendata->resolutions.count(); i++) {
  645. if ((*sortedList.at(i)) == (*screendata->resolutions.at(index))) {
  646. j=i;
  647. }
  648. }
  649. base->resolutionSlider->setValue(j);
  650. }
  651. /**** KDisplayConfig ****/
  652. KDisplayConfig::KDisplayConfig(TQWidget *parent, const char *name, const TQStringList &)
  653. : TDECModule(KDisplayCFactory::instance(), parent, name), iccTab(0), numberOfProfiles(0), numberOfScreens(0), m_randrsimple(0), activeProfileName(""), m_gammaApplyTimer(0)
  654. {
  655. TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
  656. connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*)));
  657. m_randrsimple = new KRandrSimpleAPI();
  658. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
  659. if (getuid() != 0) {
  660. systemconfig = new KSimpleConfig( locateLocal("config", "tdedisplay/", true) + "tdedisplayconfigrc" );
  661. systemconfig->setFileWriteMode(0600);
  662. }
  663. else {
  664. systemconfig = new KSimpleConfig( TQString::fromLatin1( KDE_CONFDIR "/tdedisplay/tdedisplayconfigrc" ));
  665. systemconfig->setFileWriteMode(0644);
  666. }
  667. TDEAboutData *about =
  668. new TDEAboutData(I18N_NOOP("kcmdisplayconfig"), I18N_NOOP("TDE Display Profile Control Module"),
  669. 0, 0, TDEAboutData::License_GPL,
  670. I18N_NOOP("(c) 2011 Timothy Pearson"));
  671. about->addAuthor("Timothy Pearson", 0, "kb9vqf@pearsoncomputing.net");
  672. setAboutData( about );
  673. m_gammaApplyTimer = new TQTimer();
  674. connect(m_gammaApplyTimer, SIGNAL(timeout()), this, SLOT(applyGamma()));
  675. base = new DisplayConfigBase(this);
  676. profileRulesGrid = new TQGridLayout(base->profileRulesGridWidget, 1, 1, KDialog::marginHint());
  677. layout->addWidget(base);
  678. if (getuid() != 0) {
  679. base->systemEnableSupport->setText(i18n("&Enable local display control for this session"));
  680. }
  681. // setRootOnlyMsg(i18n("<b>The global display configuration is a system wide setting, and requires administrator access</b><br>To alter the system's global display configuration, click on the \"Administrator Mode\" button below.<br>Otherwise, you may change your session-specific display configuration below."));
  682. // setUseRootOnlyMsg(true); // Setting this hides the Apply button!
  683. base->nonRootWarningLabel->setFrameShape(TQFrame::Box);
  684. base->nonRootWarningLabel->setFrameShadow(TQFrame::Raised);
  685. if (getuid() != 0) {
  686. base->nonRootWarningLabel->setText(i18n("<b>The global display configuration is a system wide setting, and requires administrator access</b><br>To alter the system's global display configuration, click on the \"Administrator Mode\" button below.<br>Otherwise, you may change your session-specific display configuration below."));
  687. }
  688. else {
  689. base->nonRootWarningLabel->hide();
  690. }
  691. connect(base->systemEnableSupport, TQT_SIGNAL(clicked()), TQT_SLOT(changed()));
  692. connect(base->systemEnableSupport, TQT_SIGNAL(clicked()), TQT_SLOT(processLockoutControls()));
  693. connect(base->addProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(addProfile()));
  694. connect(base->renameProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(renameProfile()));
  695. connect(base->deleteProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteProfile()));
  696. connect(base->activateProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(activateProfile()));
  697. connect(base->reloadProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(reloadProfileFromDisk()));
  698. connect(base->saveProfileButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(saveProfile()));
  699. connect(base->systemEnableStartupProfile, TQT_SIGNAL(clicked()), this, TQT_SLOT(changed()));
  700. connect(base->systemEnableStartupProfile, TQT_SIGNAL(clicked()), this, TQT_SLOT(processLockoutControls()));
  701. connect(base->startupDisplayProfileList, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changed()));
  702. connect(base->startupDisplayProfileList, TQT_SIGNAL(activated(int)), this, TQT_SLOT(selectDefaultProfile(int)));
  703. connect(base->displayProfileList, TQT_SIGNAL(activated(int)), this, TQT_SLOT(selectProfile(int)));
  704. connect(base->monitorDisplaySelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(changed()));
  705. connect(base->gammamonitorDisplaySelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(changed()));
  706. connect(base->gammaTargetSelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(gammaTargetChanged(int)));
  707. connect(base->rotationSelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(rotationInfoChanged()));
  708. connect(base->refreshRateDD, TQT_SIGNAL(activated(int)), TQT_SLOT(refreshInfoChanged()));
  709. connect(base->orientationHFlip, TQT_SIGNAL(clicked()), TQT_SLOT(rotationInfoChanged()));
  710. connect(base->orientationVFlip, TQT_SIGNAL(clicked()), TQT_SLOT(rotationInfoChanged()));
  711. connect(base->resolutionSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(resolutionSliderChanged(int)));
  712. connect(base->gammaAllSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(gammaAllSliderChanged(int)));
  713. connect(base->gammaRedSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(gammaRedSliderChanged(int)));
  714. connect(base->gammaGreenSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(gammaGreenSliderChanged(int)));
  715. connect(base->gammaBlueSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(gammaBlueSliderChanged(int)));
  716. connect(base->monitorDisplaySelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(selectScreen(int)));
  717. connect(base->gammamonitorDisplaySelectDD, TQT_SIGNAL(activated(int)), TQT_SLOT(gammaselectScreen(int)));
  718. connect(base->systemEnableDPMS, TQT_SIGNAL(clicked()), TQT_SLOT(dpmsChanged()));
  719. connect(base->systemEnableDPMSStandby, TQT_SIGNAL(clicked()), TQT_SLOT(dpmsChanged()));
  720. connect(base->systemEnableDPMSSuspend, TQT_SIGNAL(clicked()), TQT_SLOT(dpmsChanged()));
  721. connect(base->systemEnableDPMSPowerDown, TQT_SIGNAL(clicked()), TQT_SLOT(dpmsChanged()));
  722. connect(base->dpmsStandbyTimeout, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(dpmsChanged()));
  723. connect(base->dpmsSuspendTimeout, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(dpmsChanged()));
  724. connect(base->dpmsPowerDownTimeout, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(dpmsChanged()));
  725. connect(base->monitorPhyArrange, TQT_SIGNAL(workspaceRelayoutNeeded()), this, TQT_SLOT(layoutDragDropDisplay()));
  726. connect(base->isPrimaryMonitorCB, TQT_SIGNAL(clicked()), TQT_SLOT(changed()));
  727. connect(base->isPrimaryMonitorCB, TQT_SIGNAL(clicked()), TQT_SLOT(ensurePrimaryMonitorIsAvailable()));
  728. connect(base->isExtendedMonitorCB, TQT_SIGNAL(clicked()), TQT_SLOT(changed()));
  729. connect(base->isExtendedMonitorCB, TQT_SIGNAL(clicked()), TQT_SLOT(updateExtendedMonitorInformation()));
  730. connect(base->systemEnableSupport, TQT_SIGNAL(toggled(bool)), base->monitorDisplaySelectDD, TQT_SLOT(setEnabled(bool)));
  731. connect(base->rescanHardware, TQT_SIGNAL(clicked()), TQT_SLOT(rescanHardware()));
  732. connect(base->loadExistingProfile, TQT_SIGNAL(clicked()), TQT_SLOT(reloadProfile()));
  733. connect(base->previewConfiguration, TQT_SIGNAL(clicked()), TQT_SLOT(activatePreview()));
  734. connect(base->identifyMonitors, TQT_SIGNAL(clicked()), TQT_SLOT(identifyMonitors()));
  735. load();
  736. iccTab = addTab( "iccconfig", i18n( "Color Profiles" ) ); // [FIXME] No way to save settings here yet
  737. processLockoutControls();
  738. }
  739. KDisplayConfig::~KDisplayConfig()
  740. {
  741. delete systemconfig;
  742. if (m_gammaApplyTimer) {
  743. delete m_gammaApplyTimer;
  744. m_gammaApplyTimer = 0;
  745. }
  746. if (m_randrsimple) {
  747. delete m_randrsimple;
  748. m_randrsimple = 0;
  749. }
  750. }
  751. void KDisplayConfig::deviceChanged (TDEGenericDevice* device) {
  752. if (device->type() == TDEGenericDeviceType::Monitor) {
  753. if (base->rescanHardware->isEnabled()) {
  754. base->rescanHardware->setEnabled(false);
  755. rescanHardware();
  756. base->rescanHardware->setEnabled(true);
  757. }
  758. }
  759. }
  760. void KDisplayConfig::updateExtendedMonitorInformation () {
  761. SingleScreenData *screendata;
  762. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  763. screendata->is_extended = base->isExtendedMonitorCB->isChecked();
  764. refreshDisplayedInformation();
  765. }
  766. void KDisplayConfig::rescanHardware (void) {
  767. m_randrsimple->destroyScreenInformationObject(m_screenInfoArray[activeProfileName]);
  768. m_hardwareScreenInfoArray = m_randrsimple->readCurrentDisplayConfiguration();
  769. m_randrsimple->ensureMonitorDataConsistency(m_hardwareScreenInfoArray);
  770. m_screenInfoArray[activeProfileName] = m_randrsimple->copyScreenInformationObject(m_hardwareScreenInfoArray);
  771. numberOfScreens = m_screenInfoArray[activeProfileName].count();
  772. refreshDisplayedInformation();
  773. }
  774. void KDisplayConfig::reloadProfile (void) {
  775. m_randrsimple->ensureMonitorDataConsistency(m_screenInfoArray[activeProfileName]);
  776. numberOfScreens = m_screenInfoArray[activeProfileName].count();
  777. refreshDisplayedInformation();
  778. }
  779. void KDisplayConfig::identifyMonitors () {
  780. unsigned int i;
  781. TQLabel* idWidget;
  782. TQPtrList<TQWidget> widgetList;
  783. Display *randr_display;
  784. ScreenInfo *randr_screen_info;
  785. randr_display = tqt_xdisplay();
  786. randr_screen_info = m_randrsimple->read_screen_info(randr_display);
  787. for (i = 0; i < m_screenInfoArray[activeProfileName].count(); i++) {
  788. // Look for ON outputs...
  789. if (!randr_screen_info->outputs[i]->cur_crtc) {
  790. continue;
  791. }
  792. idWidget = new TQLabel(TQString("Screen\n%1").arg(i+1), (TQWidget*)0, "", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop | Qt::WX11BypassWM | Qt::WDestructiveClose);
  793. widgetList.append(idWidget);
  794. idWidget->resize(150, 100);
  795. idWidget->setAlignment(Qt::AlignCenter);
  796. TQFont font = idWidget->font();
  797. font.setBold( true );
  798. font.setPointSize(24);
  799. idWidget->setFont( font );
  800. idWidget->setPaletteForegroundColor(Qt::white);
  801. idWidget->setPaletteBackgroundColor(Qt::black);
  802. idWidget->show();
  803. KDialog::centerOnScreen(idWidget, i);
  804. TQTimer::singleShot(3000, idWidget, SLOT(close()));
  805. }
  806. m_randrsimple->freeScreenInfoStructure(randr_screen_info);
  807. }
  808. void KDisplayConfig::activatePreview() {
  809. m_randrsimple->applyDisplayConfiguration(m_screenInfoArray[activeProfileName], TRUE);
  810. }
  811. void KDisplayConfig::load()
  812. {
  813. load( false );
  814. }
  815. void KDisplayConfig::loadProfileFromDiskHelper(bool forceReload) {
  816. if (forceReload) {
  817. m_randrsimple->destroyScreenInformationObject(m_screenInfoArray[activeProfileName]);
  818. m_screenInfoArray.remove(activeProfileName);
  819. }
  820. if (!m_screenInfoArray.contains(activeProfileName)) {
  821. TQPtrList<SingleScreenData> originalInfoArray;
  822. TQPtrList<SingleScreenData> newInfoArray;
  823. // If a configuration is present, load it in
  824. // Otherwise, use the current display configuration
  825. originalInfoArray = m_screenInfoArray[activeProfileName];
  826. if (getuid() != 0) {
  827. newInfoArray = m_randrsimple->loadDisplayConfiguration(activeProfileName, locateLocal("config", "/", true));
  828. }
  829. else {
  830. newInfoArray = m_randrsimple->loadDisplayConfiguration(activeProfileName, KDE_CONFDIR);
  831. }
  832. if (newInfoArray.count() > 0) {
  833. m_screenInfoArray[activeProfileName] = newInfoArray;
  834. m_randrsimple->destroyScreenInformationObject(originalInfoArray);
  835. }
  836. else {
  837. m_screenInfoArray[activeProfileName] = originalInfoArray;
  838. m_randrsimple->destroyScreenInformationObject(newInfoArray);
  839. }
  840. }
  841. // If there is still no valid configuration, read the active display information from the hardware
  842. // to initialise the configuration...
  843. if (m_screenInfoArray[activeProfileName].count() < 1) {
  844. m_hardwareScreenInfoArray = m_randrsimple->readCurrentDisplayConfiguration();
  845. m_randrsimple->ensureMonitorDataConsistency(m_hardwareScreenInfoArray);
  846. m_screenInfoArray[activeProfileName] = m_randrsimple->copyScreenInformationObject(m_hardwareScreenInfoArray);
  847. }
  848. m_randrsimple->ensureMonitorDataConsistency(m_screenInfoArray[activeProfileName]);
  849. numberOfScreens = m_screenInfoArray[activeProfileName].count();
  850. reloadProfile();
  851. }
  852. void KDisplayConfig::selectProfile (int slotNumber) {
  853. TQString selectedProfile = base->displayProfileList->currentText();
  854. if (selectedProfile == "<default>") {
  855. selectedProfile = "";
  856. }
  857. activeProfileName = selectedProfile;
  858. loadProfileFromDiskHelper();
  859. }
  860. void KDisplayConfig::deleteProfile () {
  861. if (activeProfileName == "") {
  862. KMessageBox::sorry(this, i18n("You cannot delete the default profile!"), i18n("Invalid operation requested"));
  863. return;
  864. }
  865. int ret = KMessageBox::warningYesNo(this, i18n("<qt><b>You are attempting to delete the display profile '%1'</b><br>If you click Yes, the profile will be permanently removed from disk<p>Do you want to delete this profile?</qt>").arg(activeProfileName), i18n("Delete display profile?"));
  866. if (ret == KMessageBox::Yes) {
  867. bool success = false;
  868. if (getuid() != 0) {
  869. success = m_randrsimple->deleteDisplayConfiguration(activeProfileName, locateLocal("config", "/", true));
  870. }
  871. else {
  872. success = m_randrsimple->deleteDisplayConfiguration(activeProfileName, KDE_CONFDIR);
  873. }
  874. if (success) {
  875. TQStringList::Iterator it = availableProfileNames.find(activeProfileName);
  876. if (it != availableProfileNames.end()) {
  877. availableProfileNames.remove(it);
  878. }
  879. profileListChanged();
  880. selectProfile(base->displayProfileList->currentItem());
  881. }
  882. else {
  883. KMessageBox::error(this, i18n("<qt><b>Unable to delete profile '%1'!</b><p>Please verify that you have permission to access the configuration file</qt>").arg(activeProfileName), i18n("Deletion failed!"));
  884. }
  885. }
  886. }
  887. void KDisplayConfig::renameProfile () {
  888. if (activeProfileName == "") {
  889. KMessageBox::sorry(this, i18n("You cannot rename the default profile!"), i18n("Invalid operation requested"));
  890. return;
  891. }
  892. // Pop up a text entry box asking for the new name of the profile
  893. bool _ok = false;
  894. bool _end = false;
  895. TQString _new;
  896. TQString _text = i18n("Please enter the new profile name below:");
  897. TQString _error;
  898. while (!_end) {
  899. _new = KInputDialog::getText( i18n("Display Profile Configuration"), _error + _text, activeProfileName, &_ok, this);
  900. if (!_ok ) {
  901. _end = true;
  902. }
  903. else {
  904. _error = TQString();
  905. if (!_new.isEmpty()) {
  906. if (findProfileIndex(_new) != -1) {
  907. _error = i18n("Error: A profile with that name already exists") + TQString("\n");
  908. }
  909. else {
  910. _end = true;
  911. }
  912. }
  913. }
  914. }
  915. if (!_ok) return;
  916. bool success = false;
  917. if (getuid() != 0) {
  918. success = m_randrsimple->renameDisplayConfiguration(activeProfileName, _new, locateLocal("config", "/", true));
  919. }
  920. else {
  921. success = m_randrsimple->renameDisplayConfiguration(activeProfileName, _new, KDE_CONFDIR);
  922. }
  923. if (success) {
  924. TQStringList::Iterator it = availableProfileNames.find(activeProfileName);
  925. if (it != availableProfileNames.end()) {
  926. availableProfileNames.remove(it);
  927. }
  928. availableProfileNames.append(_new);
  929. profileListChanged();
  930. base->displayProfileList->setCurrentItem(_new);
  931. selectProfile(base->displayProfileList->currentItem());
  932. }
  933. else {
  934. KMessageBox::error(this, i18n("<qt><b>Unable to rename profile '%1'!</b><p>Please verify that you have permission to access the configuration file</qt>").arg(activeProfileName), i18n("Renaming failed!"));
  935. }
  936. }
  937. void KDisplayConfig::activateProfile() {
  938. if (getuid() != 0) {
  939. m_randrsimple->applyDisplayConfiguration(m_screenInfoArray[activeProfileName], TRUE, locateLocal("config", "/", true));
  940. }
  941. else {
  942. m_randrsimple->applyDisplayConfiguration(m_screenInfoArray[activeProfileName], TRUE, KDE_CONFDIR);
  943. }
  944. rescanHardware();
  945. }
  946. void KDisplayConfig::reloadProfileFromDisk() {
  947. loadProfileFromDiskHelper(true);
  948. }
  949. void KDisplayConfig::saveProfile() {
  950. saveActiveSystemWideProfileToDisk();
  951. }
  952. void KDisplayConfig::addProfile () {
  953. // Pop up a text entry box asking for the name of the new profile
  954. bool _ok = false;
  955. bool _end = false;
  956. TQString _new;
  957. TQString _text = i18n("Please enter the new profile name below:");
  958. TQString _error;
  959. while (!_end) {
  960. _new = KInputDialog::getText( i18n("Display Profile Configuration"), _error + _text, TQString::null, &_ok, this);
  961. if (!_ok ) {
  962. _end = true;
  963. }
  964. else {
  965. _error = TQString();
  966. if (!_new.isEmpty()) {
  967. if (findProfileIndex(_new) != -1) {
  968. _error = i18n("Error: A profile with that name already exists") + TQString("\n");
  969. }
  970. else {
  971. _end = true;
  972. }
  973. }
  974. }
  975. }
  976. if (!_ok) return;
  977. m_screenInfoArray[_new] = m_randrsimple->copyScreenInformationObject(m_screenInfoArray[activeProfileName]);
  978. // Insert the new profile name
  979. availableProfileNames.append(_new);
  980. profileListChanged();
  981. base->displayProfileList->setCurrentItem(_new);
  982. selectProfile(base->displayProfileList->currentItem());
  983. updateDisplayedInformation();
  984. saveActiveSystemWideProfileToDisk();
  985. emit changed();
  986. }
  987. void KDisplayConfig::updateStartupProfileLabel()
  988. {
  989. TQString friendlyName = startupProfileName;
  990. if (friendlyName == "") {
  991. friendlyName = "<default>";
  992. }
  993. base->startupDisplayProfileList->setCurrentItem(friendlyName, false);
  994. }
  995. void KDisplayConfig::selectDefaultProfile(int slotNumber)
  996. {
  997. TQString selectedProfile = base->startupDisplayProfileList->currentText();
  998. if (selectedProfile == "<default>") {
  999. selectedProfile = "";
  1000. }
  1001. startupProfileName = selectedProfile;
  1002. }
  1003. void KDisplayConfig::selectScreen (int slotNumber) {
  1004. base->monitorDisplaySelectDD->setCurrentItem(slotNumber);
  1005. base->gammamonitorDisplaySelectDD->setCurrentItem(slotNumber);
  1006. updateDisplayedInformation();
  1007. }
  1008. void KDisplayConfig::updateArray (void) {
  1009. m_hardwareScreenInfoArray = m_randrsimple->readCurrentDisplayConfiguration();
  1010. m_randrsimple->ensureMonitorDataConsistency(m_hardwareScreenInfoArray);
  1011. m_screenInfoArray[activeProfileName] = m_randrsimple->copyScreenInformationObject(m_hardwareScreenInfoArray);
  1012. numberOfScreens = m_screenInfoArray[activeProfileName].count();
  1013. }
  1014. void KDisplayConfig::updateDisplayedInformation () {
  1015. // Insert data into the GUI
  1016. unsigned int i;
  1017. SingleScreenData *screendata;
  1018. ensureMonitorDataConsistency();
  1019. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  1020. if (!screendata) {
  1021. base->resolutionSlider->setEnabled(false);
  1022. base->refreshRateDD->setEnabled(false);
  1023. base->rotationSelectDD->setEnabled(false);
  1024. base->orientationHFlip->setEnabled(false);
  1025. base->orientationVFlip->setEnabled(false);
  1026. base->isPrimaryMonitorCB->setEnabled(false);
  1027. base->isExtendedMonitorCB->setEnabled(false);
  1028. return;
  1029. }
  1030. if (screendata->screen_connected) {
  1031. base->resolutionSlider->setEnabled(true);
  1032. base->refreshRateDD->setEnabled(true);
  1033. base->rotationSelectDD->setEnabled(true);
  1034. base->orientationHFlip->setEnabled(true);
  1035. base->orientationVFlip->setEnabled(true);
  1036. base->isPrimaryMonitorCB->setEnabled(true);
  1037. base->isExtendedMonitorCB->setEnabled(true);
  1038. }
  1039. // Update the resolutions for the selected screen
  1040. base->resolutionSlider->blockSignals(true);
  1041. base->resolutionSlider->setMaxValue(screendata->resolutions.count()-1);
  1042. setRealResolutionSliderValue(screendata->current_resolution_index);
  1043. resolutionSliderTextUpdate(realResolutionSliderValue());
  1044. base->resolutionSlider->blockSignals(false);
  1045. // Now the refresh rates for the selected screen
  1046. base->refreshRateDD->blockSignals(true);
  1047. base->refreshRateDD->clear();
  1048. for (i=0;i<screendata->refresh_rates.count();i++) {
  1049. base->refreshRateDD->insertItem(screendata->refresh_rates[i], i);
  1050. }
  1051. base->refreshRateDD->setCurrentItem(screendata->current_refresh_rate_index);
  1052. base->refreshRateDD->blockSignals(false);
  1053. // Now the rotations and transformations for the selected screen
  1054. base->rotationSelectDD->blockSignals(true);
  1055. base->orientationHFlip->blockSignals(true);
  1056. base->orientationVFlip->blockSignals(true);
  1057. base->rotationSelectDD->clear();
  1058. if (screendata->supports_transformations) {
  1059. for (i=0;i<screendata->rotations.count();i++) {
  1060. base->rotationSelectDD->insertItem(screendata->rotations[i], i);
  1061. }
  1062. base->rotationSelectDD->setCurrentItem(screendata->current_rotation_index);
  1063. base->orientationHFlip->show();
  1064. base->orientationVFlip->show();
  1065. base->orientationHFlip->setChecked(screendata->has_x_flip);
  1066. base->orientationVFlip->setChecked(screendata->has_y_flip);
  1067. }
  1068. else {
  1069. base->rotationSelectDD->insertItem(ROTATION_0_DEGREES_STRING, 0);
  1070. base->rotationSelectDD->setCurrentItem(0);
  1071. base->orientationHFlip->hide();
  1072. base->orientationVFlip->hide();
  1073. }
  1074. base->rotationSelectDD->blockSignals(false);
  1075. base->orientationHFlip->blockSignals(false);
  1076. base->orientationVFlip->blockSignals(false);
  1077. base->isPrimaryMonitorCB->blockSignals(true);
  1078. base->isExtendedMonitorCB->blockSignals(true);
  1079. if (screendata->generic_screen_detected) {
  1080. base->isPrimaryMonitorCB->setEnabled(false);
  1081. base->isPrimaryMonitorCB->setChecked(true);
  1082. base->isExtendedMonitorCB->setEnabled(false);
  1083. base->isExtendedMonitorCB->setChecked(true);
  1084. }
  1085. else {
  1086. base->isPrimaryMonitorCB->setEnabled(true);
  1087. base->isPrimaryMonitorCB->setChecked(screendata->is_primary);
  1088. if (screendata->is_primary) {
  1089. base->isExtendedMonitorCB->setEnabled(false);
  1090. base->isExtendedMonitorCB->setChecked(true);
  1091. }
  1092. else {
  1093. base->isExtendedMonitorCB->setEnabled(true);
  1094. base->isExtendedMonitorCB->setChecked(screendata->is_extended);
  1095. }
  1096. }
  1097. base->isPrimaryMonitorCB->blockSignals(false);
  1098. base->isExtendedMonitorCB->blockSignals(false);
  1099. if (!screendata->screen_connected) {
  1100. base->resolutionSlider->setEnabled(false);
  1101. base->refreshRateDD->setEnabled(false);
  1102. base->rotationSelectDD->setEnabled(false);
  1103. base->orientationHFlip->setEnabled(false);
  1104. base->orientationVFlip->setEnabled(false);
  1105. base->isPrimaryMonitorCB->setEnabled(false);
  1106. base->isExtendedMonitorCB->setEnabled(false);
  1107. }
  1108. }
  1109. void KDisplayConfig::refreshDisplayedInformation () {
  1110. createHotplugRulesGrid();
  1111. // Insert data into the GUI
  1112. int i;
  1113. SingleScreenData *screendata;
  1114. // First, the screens
  1115. int currentScreenIndex = base->monitorDisplaySelectDD->currentItem();
  1116. base->monitorDisplaySelectDD->clear();
  1117. for (i=0;i<numberOfScreens;i++) {
  1118. screendata = m_screenInfoArray[activeProfileName].at(i);
  1119. base->monitorDisplaySelectDD->insertItem(screendata->screenFriendlyName, i);
  1120. }
  1121. base->monitorDisplaySelectDD->setCurrentItem(currentScreenIndex);
  1122. base->gammamonitorDisplaySelectDD->clear();
  1123. for (i=0;i<numberOfScreens;i++) {
  1124. screendata = m_screenInfoArray[activeProfileName].at(i);
  1125. base->gammamonitorDisplaySelectDD->insertItem(screendata->screenFriendlyName, i);
  1126. }
  1127. base->gammamonitorDisplaySelectDD->setCurrentItem(currentScreenIndex);
  1128. updateDisplayedInformation();
  1129. updateDragDropDisplay();
  1130. screendata = m_screenInfoArray[activeProfileName].at(0);
  1131. if (screendata) {
  1132. base->groupPowerManagement->setEnabled(true);
  1133. base->systemEnableDPMS->setEnabled(screendata->has_dpms);
  1134. base->systemEnableDPMS->setChecked(screendata->enable_dpms);
  1135. base->systemEnableDPMSStandby->setChecked(screendata->dpms_standby_delay!=0);
  1136. base->systemEnableDPMSSuspend->setChecked(screendata->dpms_suspend_delay!=0);
  1137. base->systemEnableDPMSPowerDown->setChecked(screendata->dpms_off_delay!=0);
  1138. base->dpmsStandbyTimeout->setValue(screendata->dpms_standby_delay/60);
  1139. base->dpmsSuspendTimeout->setValue(screendata->dpms_suspend_delay/60);
  1140. base->dpmsPowerDownTimeout->setValue(screendata->dpms_off_delay/60);
  1141. }
  1142. else {
  1143. base->groupPowerManagement->setEnabled(false);
  1144. }
  1145. processDPMSControls();
  1146. }
  1147. void KDisplayConfig::updateDragDropDisplay() {
  1148. // Insert data into the GUI
  1149. int i;
  1150. int j;
  1151. TQObjectList monitors;
  1152. SingleScreenData *screendata;
  1153. // Clear any screens from the workspace
  1154. monitors = base->monitorPhyArrange->childrenListObject();
  1155. if ( monitors.count() ) {
  1156. for ( i = 0; i < int(monitors.count()); ++i ) {
  1157. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  1158. TQWidget *monitor = TQT_TQWIDGET(monitors.at( i ));
  1159. if ( !monitor->close(TRUE) ) {
  1160. Q_ASSERT("zombie monitor will not go away!");
  1161. }
  1162. }
  1163. }
  1164. }
  1165. ensureMonitorDataConsistency();
  1166. // Add the screens to the workspace
  1167. // Set the scaling small to start with
  1168. base->monitorPhyArrange->resize_factor = 0.0625; // This always needs to divide by a multiple of 2
  1169. for (j=0;j<2;j++) {
  1170. for (i=0;i<numberOfScreens;i++) {
  1171. screendata = m_screenInfoArray[activeProfileName].at(i);
  1172. if (((j==0) && (screendata->is_primary==true)) || ((j==1) && (screendata->is_primary==false))) { // This ensures that the primary monitor is always the first one created and placed on the configuration widget
  1173. TQString rotationDesired = *screendata->rotations.at(screendata->current_rotation_index);
  1174. bool isvisiblyrotated = ((rotationDesired == ROTATION_90_DEGREES_STRING) || (rotationDesired == ROTATION_270_DEGREES_STRING));
  1175. DraggableMonitor *m = new DraggableMonitor( base->monitorPhyArrange, 0, WStyle_Customize | WDestructiveClose | WStyle_NoBorder | WX11BypassWM );
  1176. connect(m, TQT_SIGNAL(workspaceRelayoutNeeded()), this, TQT_SLOT(layoutDragDropDisplay()));
  1177. connect(m, TQT_SIGNAL(monitorSelected(int)), this, TQT_SLOT(selectScreen(int)));
  1178. connect(m, TQT_SIGNAL(monitorDragComplete(int)), this, TQT_SLOT(updateDraggableMonitorInformation(int)));
  1179. m->screen_id = i;
  1180. if (isvisiblyrotated)
  1181. m->setFixedSize(screendata->current_y_pixel_count*base->monitorPhyArrange->resize_factor, screendata->current_x_pixel_count*base->monitorPhyArrange->resize_factor);
  1182. else
  1183. m->setFixedSize(screendata->current_x_pixel_count*base->monitorPhyArrange->resize_factor, screendata->current_y_pixel_count*base->monitorPhyArrange->resize_factor);
  1184. m->setText(TQString("%1").arg(i+1));
  1185. m->show();
  1186. moveMonitor(m, screendata->absolute_x_position, screendata->absolute_y_position);
  1187. updateDraggableMonitorInformation(i); // Make sure the new monitors don't overlap
  1188. }
  1189. }
  1190. }
  1191. layoutDragDropDisplay();
  1192. }
  1193. void KDisplayConfig::layoutDragDropDisplay() {
  1194. int i;
  1195. TQObjectList monitors;
  1196. SingleScreenData *screendata;
  1197. // Ensure data is consistent
  1198. ensureMonitorDataConsistency();
  1199. // Arrange the screens
  1200. // First, center the primary monitor
  1201. monitors = base->monitorPhyArrange->childrenListObject();
  1202. if ( monitors.count() ) {
  1203. for ( i = 0; i < int(monitors.count()); ++i ) {
  1204. if (::tqqt_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )))) {
  1205. DraggableMonitor *monitor = static_cast<DraggableMonitor*>(TQT_TQWIDGET(monitors.at( i )));
  1206. screendata = m_screenInfoArray[activeProfileName].at(monitor->screen_id);
  1207. moveMonitor(monitor, screendata->absolute_x_position, screendata->absolute_y_position);
  1208. }
  1209. }
  1210. }
  1211. }
  1212. void KDisplayConfig::ensureMonitorDataConsistency() {
  1213. m_randrsimple->ensureMonitorDataConsistency(m_screenInfoArray[activeProfileName]);
  1214. }
  1215. void KDisplayConfig::resolutionSliderTextUpdate(int index) {
  1216. SingleScreenData *screendata;
  1217. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  1218. base->resolutionLabel->setText(screendata->resolutions[realResolutionSliderValue()] + TQString(" ") + i18n("pixels"));
  1219. }
  1220. void KDisplayConfig::resolutionSliderChanged(int index) {
  1221. SingleScreenData *screendata;
  1222. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  1223. screendata->current_resolution_index = realResolutionSliderValue();
  1224. updateDisplayedInformation();
  1225. updateDraggableMonitorInformation(base->monitorDisplaySelectDD->currentItem());
  1226. applyMonitorLayoutRules();
  1227. changed();
  1228. }
  1229. void KDisplayConfig::rotationInfoChanged() {
  1230. SingleScreenData *screendata;
  1231. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  1232. screendata->current_rotation_index = base->rotationSelectDD->currentItem();
  1233. screendata->has_x_flip = base->orientationHFlip->isChecked();
  1234. screendata->has_y_flip = base->orientationVFlip->isChecked();
  1235. updateDisplayedInformation();
  1236. updateDraggableMonitorInformation(base->monitorDisplaySelectDD->currentItem());
  1237. applyMonitorLayoutRules();
  1238. changed();
  1239. }
  1240. void KDisplayConfig::refreshInfoChanged() {
  1241. SingleScreenData *screendata;
  1242. screendata = m_screenInfoArray[activeProfileName].at(base->monitorDisplaySelectDD->currentItem());
  1243. screendata->current_refresh_rate_index = base->refreshRateDD->currentItem();
  1244. updateDisplayedInformation();
  1245. updateDraggableMonitorInformation(base->monitorDisplaySelectDD->currentItem());
  1246. changed();
  1247. }
  1248. void KDisplayConfig::ensurePrimaryMonitorIsAvailable() {
  1249. // Ensure that only one monitor, and not less than one monitor, is marked as primary
  1250. int i;
  1251. SingleScreenData *screendata;
  1252. // First, the screens
  1253. int currentScreenIndex = base->monitorDisplaySelectDD->currentItem();
  1254. for (i=0;i<numberOfScreens;i++) {
  1255. screendata = m_screenInfoArray[activeProfileName].at(i);
  1256. if (i != currentScreenIndex)
  1257. screendata->is_primary = false;
  1258. }
  1259. screendata = m_screenInfoArray[activeProfileName].at(currentScreenIndex);
  1260. screendata->is_primary = true;
  1261. screendata->is_extended = true;
  1262. updateDragDropDisplay();
  1263. refreshDisplayedInformation();
  1264. }
  1265. int KDisplayConfig::findProfileIndex(TQString profileName) {
  1266. int i;
  1267. for (i=0;i<base->displayProfileList->count();i++) {
  1268. if (base->displayProfileList->text(i) == profileName) {
  1269. return i;
  1270. }
  1271. }
  1272. return -1;
  1273. }
  1274. void KDisplayConfig::setGammaLabels() {
  1275. SingleScreenData *screendata;
  1276. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1277. // Round off the gammas to one decimal place
  1278. screendata->gamma_red = floorf(screendata->gamma_red * 10 + 0.5) / 10;
  1279. screendata->gamma_green = floorf(screendata->gamma_green * 10 + 0.5) / 10;
  1280. screendata->gamma_blue = floorf(screendata->gamma_blue * 10 + 0.5) / 10;
  1281. // Set the labels
  1282. base->gammaAllLabel->setText(TQString("%1").arg(((float)base->gammaAllSlider->value())/10.0, 0, 'f', 1));
  1283. base->gammaRedLabel->setText(TQString("%1").arg(((float)base->gammaRedSlider->value())/10.0, 0, 'f', 1));
  1284. base->gammaGreenLabel->setText(TQString("%1").arg(((float)base->gammaGreenSlider->value())/10.0, 0, 'f', 1));
  1285. base->gammaBlueLabel->setText(TQString("%1").arg(((float)base->gammaBlueSlider->value())/10.0, 0, 'f', 1));
  1286. }
  1287. void KDisplayConfig::gammaSetAverageAllSlider() {
  1288. float average_gamma;
  1289. SingleScreenData *screendata;
  1290. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1291. average_gamma = (screendata->gamma_red+screendata->gamma_green+screendata->gamma_blue)/3.0;
  1292. average_gamma = floorf(average_gamma* 10 + 0.5) / 10; // Round off the gamma to one decimal place
  1293. base->gammaAllSlider->setValue(average_gamma*10.0);
  1294. }
  1295. void KDisplayConfig::gammaselectScreen (int slotNumber) {
  1296. SingleScreenData *screendata;
  1297. base->gammaAllSlider->blockSignals(true);
  1298. base->gammaRedSlider->blockSignals(true);
  1299. base->gammaGreenSlider->blockSignals(true);
  1300. base->gammaBlueSlider->blockSignals(true);
  1301. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1302. base->gammaRedSlider->setValue(screendata->gamma_red*10.0);
  1303. base->gammaGreenSlider->setValue(screendata->gamma_green*10.0);
  1304. base->gammaBlueSlider->setValue(screendata->gamma_blue*10.0);
  1305. gammaSetAverageAllSlider();
  1306. setGammaLabels();
  1307. base->gammaAllSlider->blockSignals(false);
  1308. base->gammaRedSlider->blockSignals(false);
  1309. base->gammaGreenSlider->blockSignals(false);
  1310. base->gammaBlueSlider->blockSignals(false);
  1311. }
  1312. void KDisplayConfig::gammaAllSliderChanged(int index) {
  1313. SingleScreenData *screendata;
  1314. base->gammaAllSlider->blockSignals(true);
  1315. base->gammaRedSlider->blockSignals(true);
  1316. base->gammaGreenSlider->blockSignals(true);
  1317. base->gammaBlueSlider->blockSignals(true);
  1318. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1319. base->gammaRedSlider->setValue(base->gammaAllSlider->value());
  1320. base->gammaGreenSlider->setValue(base->gammaAllSlider->value());
  1321. base->gammaBlueSlider->setValue(base->gammaAllSlider->value());
  1322. setGammaLabels();
  1323. screendata->gamma_red = ((float)base->gammaAllSlider->value())/10.0;
  1324. screendata->gamma_green = ((float)base->gammaAllSlider->value())/10.0;
  1325. screendata->gamma_blue = ((float)base->gammaAllSlider->value())/10.0;
  1326. m_gammaApplyTimer->start(10, TRUE);
  1327. base->gammaAllSlider->blockSignals(false);
  1328. base->gammaRedSlider->blockSignals(false);
  1329. base->gammaGreenSlider->blockSignals(false);
  1330. base->gammaBlueSlider->blockSignals(false);
  1331. changed();
  1332. }
  1333. void KDisplayConfig::gammaRedSliderChanged(int index) {
  1334. SingleScreenData *screendata;
  1335. base->gammaAllSlider->blockSignals(true);
  1336. base->gammaRedSlider->blockSignals(true);
  1337. base->gammaGreenSlider->blockSignals(true);
  1338. base->gammaBlueSlider->blockSignals(true);
  1339. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1340. screendata->gamma_red = ((float)index)/10.0;
  1341. gammaSetAverageAllSlider();
  1342. setGammaLabels();
  1343. m_gammaApplyTimer->start(10, TRUE);
  1344. base->gammaAllSlider->blockSignals(false);
  1345. base->gammaRedSlider->blockSignals(false);
  1346. base->gammaGreenSlider->blockSignals(false);
  1347. base->gammaBlueSlider->blockSignals(false);
  1348. changed();
  1349. }
  1350. void KDisplayConfig::gammaGreenSliderChanged(int index) {
  1351. SingleScreenData *screendata;
  1352. base->gammaAllSlider->blockSignals(true);
  1353. base->gammaRedSlider->blockSignals(true);
  1354. base->gammaGreenSlider->blockSignals(true);
  1355. base->gammaBlueSlider->blockSignals(true);
  1356. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1357. screendata->gamma_green = ((float)index)/10.0;
  1358. gammaSetAverageAllSlider();
  1359. setGammaLabels();
  1360. m_gammaApplyTimer->start(10, TRUE);
  1361. base->gammaAllSlider->blockSignals(false);
  1362. base->gammaRedSlider->blockSignals(false);
  1363. base->gammaGreenSlider->blockSignals(false);
  1364. base->gammaBlueSlider->blockSignals(false);
  1365. changed();
  1366. }
  1367. void KDisplayConfig::gammaBlueSliderChanged(int index) {
  1368. SingleScreenData *screendata;
  1369. base->gammaAllSlider->blockSignals(true);
  1370. base->gammaRedSlider->blockSignals(true);
  1371. base->gammaGreenSlider->blockSignals(true);
  1372. base->gammaBlueSlider->blockSignals(true);
  1373. screendata = m_screenInfoArray[activeProfileName].at(base->gammamonitorDisplaySelectDD->currentItem());
  1374. screendata->gamma_blue = ((float)index)/10.0;
  1375. gammaSetAverageAllSlider();
  1376. setGammaLabels();
  1377. m_gammaApplyTimer->start(10, TRUE);
  1378. base->gammaAllSlider->blockSignals(false);
  1379. base->gammaRedSlider->blockSignals(false);
  1380. base->gammaGreenSlider->blockSignals(false);
  1381. base->gammaBlueSlider->blockSignals(false);
  1382. changed();
  1383. }
  1384. void KDisplayConfig::applyGamma() {
  1385. m_randrsimple->applyDisplayGamma(m_screenInfoArray[activeProfileName]);
  1386. }
  1387. void KDisplayConfig::gammaTargetChanged (int slotNumber) {
  1388. TQPixmap gammaPixmap( locate("data", TQString("kcontrol/pics/gamma%1.png").arg(base->gammaTargetSelectDD->text(slotNumber))) );
  1389. base->gammaTestImage->setBackgroundPixmap( gammaPixmap );
  1390. }
  1391. void KDisplayConfig::dpmsChanged() {
  1392. SingleScreenData *screendata;
  1393. screendata = m_screenInfoArray[activeProfileName].at(0);
  1394. processDPMSControls();
  1395. screendata->enable_dpms = base->systemEnableDPMS->isChecked();
  1396. screendata->dpms_standby_delay = (base->systemEnableDPMSStandby->isChecked())?base->dpmsStandbyTimeout->value()*60:0;
  1397. screendata->dpms_suspend_delay = (base->systemEnableDPMSSuspend->isChecked())?base->dpmsSuspendTimeout->value()*60:0;
  1398. screendata->dpms_off_delay = (base->systemEnableDPMSPowerDown->isChecked())?base->dpmsPowerDownTimeout->value()*60:0;
  1399. changed();
  1400. }
  1401. void KDisplayConfig::createHotplugRulesGrid() {
  1402. const TQObjectList children = base->profileRulesGridWidget->childrenListObject();
  1403. TQObjectList::iterator it = children.begin();
  1404. for (; it != children.end(); ++it) {
  1405. TQWidget *w = dynamic_cast<TQWidget*>(*it);
  1406. if (w) {
  1407. delete w;
  1408. }
  1409. }
  1410. int i = 0;
  1411. int j = 0;
  1412. TQLabel* label;
  1413. SingleScreenData *screendata;
  1414. for (i=0;i<numberOfScreens;i++) {
  1415. screendata = m_hardwareScreenInfoArray.at(i);
  1416. label = new TQLabel(base->profileRulesGridWidget, (TQString("%1").arg(i)).ascii());
  1417. if (screendata) {
  1418. label->setText(screendata->screenUniqueName);
  1419. }
  1420. profileRulesGrid->addWidget(label, 0, i);
  1421. label->show();
  1422. }
  1423. label = new TQLabel(base->profileRulesGridWidget, "<ignore>");
  1424. label->setText(i18n("Activate Profile on Match"));
  1425. profileRulesGrid->addWidget(label, 0, i+1);
  1426. label->show();
  1427. i=0;
  1428. HotPlugRulesList::Iterator it2;
  1429. for (it2=currentHotplugRules.begin(); it2 != currentHotplugRules.end(); ++it2) {
  1430. for (j=0;j<numberOfScreens;j++) {
  1431. int index = (*it2).outputs.findIndex(m_hardwareScreenInfoArray.at(j)->screenUniqueName);
  1432. TQCheckBox* cb = new TQCheckBox(base->profileRulesGridWidget, (TQString("%1:%2").arg(i).arg(j)).ascii());
  1433. connect(cb, TQT_SIGNAL(stateChanged(int)), this, TQT_SLOT(profileRuleCheckBoxStateChanged(int)));
  1434. connect(cb, TQT_SIGNAL(stateChanged(int)), this, TQT_SLOT(changed()));
  1435. cb->setTristate(true);
  1436. if (index < 0) {
  1437. cb->setNoChange();
  1438. }
  1439. else {
  1440. switch ((*it2).states[index]) {
  1441. case HotPlugRule::AnyState:
  1442. cb->setNoChange();
  1443. break;
  1444. case HotPlugRule::Connected:
  1445. cb->setChecked(true);
  1446. break;
  1447. case HotPlugRule::Disconnected:
  1448. cb->setChecked(false);
  1449. break;
  1450. }
  1451. }
  1452. profileRulesGrid->addWidget(cb, i+1, j);
  1453. cb->show();
  1454. }
  1455. KComboBox* combo = new KComboBox(base->profileRulesGridWidget, (TQString("%1").arg(i)).ascii());
  1456. connect(combo, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changed()));
  1457. combo->insertItem("<default>");
  1458. for (TQStringList::Iterator it3 = availableProfileNames.begin(); it3 != availableProfileNames.end(); ++it3) {
  1459. combo->insertItem(*it3);
  1460. }
  1461. combo->setCurrentItem((*it2).profileName);
  1462. profileRulesGrid->addWidget(combo, i+1, j+1);
  1463. combo->show();
  1464. TQPushButton* button = new TQPushButton(base->profileRulesGridWidget, (TQString("%1").arg(i)).ascii());
  1465. button->setText(i18n("Delete Rule"));
  1466. connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteProfileRule()));
  1467. connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(changed()));
  1468. profileRulesGrid->addWidget(button, i+1, j+2);
  1469. button->show();
  1470. i++;
  1471. }
  1472. TQPushButton* button = new TQPushButton(base->profileRulesGridWidget);
  1473. button->setText(i18n("Add New Rule"));
  1474. connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(addNewProfileRule()));
  1475. connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(changed()));
  1476. profileRulesGrid->addMultiCellWidget(button, i+2, i+2, 0, numberOfScreens+2);
  1477. button->show();
  1478. }
  1479. void KDisplayConfig::addNewProfileRule() {
  1480. currentHotplugRules.append(HotPlugRule());
  1481. createHotplugRulesGrid();
  1482. }
  1483. void KDisplayConfig::deleteProfileRule() {
  1484. const TQWidget* w = dynamic_cast<const TQWidget*>(sender());
  1485. if (w) {
  1486. int row = atoi(w->name());
  1487. currentHotplugRules.remove(currentHotplugRules.at(row));
  1488. createHotplugRulesGrid();
  1489. }
  1490. }
  1491. void KDisplayConfig::profileRuleCheckBoxStateChanged(int state) {
  1492. updateProfileConfigObjectFromGrid();
  1493. emit(changed());
  1494. }
  1495. void KDisplayConfig::updateProfileConfigObjectFromGrid() {
  1496. const TQObjectList children = base->profileRulesGridWidget->childrenListObject();
  1497. TQObjectList::iterator it = children.begin();
  1498. for (; it != children.end(); ++it) {
  1499. TQWidget *w = dynamic_cast<TQWidget*>(*it);
  1500. TQCheckBox *cb = dynamic_cast<TQCheckBox*>(w);
  1501. TQComboBox *combo = dynamic_cast<TQComboBox*>(w);
  1502. TQLabel* label = dynamic_cast<TQLabel*>(w);
  1503. if (label) {
  1504. if (TQString(w->name()) != TQString("<ignore>")) {
  1505. int col = atoi(w->name());
  1506. HotPlugRulesList::Iterator it2;
  1507. for (it2=currentHotplugRules.begin(); it2 != currentHotplugRules.end(); ++it2) {
  1508. TQStringList &strlist = (*it2).outputs;
  1509. while (strlist.count() < (uint)numberOfScreens) {
  1510. strlist.append("");
  1511. }
  1512. while (strlist.count() > (uint)numberOfScreens) {
  1513. strlist.remove(strlist.at(strlist.count()-1));
  1514. }
  1515. strlist[col] = label->text();
  1516. }
  1517. }
  1518. }
  1519. if (cb) {
  1520. TQStringList rowcol = TQStringList::split(":", cb->name());
  1521. int row = atoi(rowcol[0].ascii());
  1522. int col = atoi(rowcol[1].ascii());
  1523. TQValueList<int> &intlist = (*(currentHotplugRules.at(row))).states;
  1524. while (intlist.count() < (uint)numberOfScreens) {
  1525. intlist.append(HotPlugRule::AnyState);
  1526. }
  1527. while (intlist.count() > (uint)numberOfScreens) {
  1528. intlist.remove(intlist.at(intlist.count()-1));
  1529. }
  1530. int state = cb->state();
  1531. if (state == TQButton::On) {
  1532. intlist[col] = HotPlugRule::Connected;
  1533. }
  1534. else if (state == TQButton::Off) {
  1535. intlist[col] = HotPlugRule::Disconnected;
  1536. }
  1537. else {
  1538. intlist[col] = HotPlugRule::AnyState;
  1539. }
  1540. }
  1541. if (combo) {
  1542. int row = atoi(w->name());
  1543. (*(currentHotplugRules.at(row))).profileName = combo->currentText();
  1544. }
  1545. }
  1546. }
  1547. void KDisplayConfig::profileListChanged() {
  1548. // Save selected profile settings
  1549. TQString currentDisplayProfileListItem = base->displayProfileList->currentText();
  1550. TQString currentStartupDisplayProfileListItem = base->startupDisplayProfileList->currentText();
  1551. // Clear and reload the combo boxes
  1552. base->displayProfileList->clear();
  1553. base->startupDisplayProfileList->clear();
  1554. base->displayProfileList->insertItem("<default>");
  1555. base->startupDisplayProfileList->insertItem("<default>");
  1556. for (TQStringList::Iterator it = availableProfileNames.begin(); it != availableProfileNames.end(); ++it) {
  1557. base->displayProfileList->insertItem(*it);
  1558. base->startupDisplayProfileList->insertItem(*it);
  1559. }
  1560. // Restore selected profile settings if possible
  1561. if (base->displayProfileList->contains(currentDisplayProfileListItem)) {
  1562. base->displayProfileList->setCurrentItem(currentDisplayProfileListItem);
  1563. }
  1564. else {
  1565. base->displayProfileList->setCurrentItem(0);
  1566. }
  1567. if (base->startupDisplayProfileList->contains(currentStartupDisplayProfileListItem)) {
  1568. base->startupDisplayProfileList->setCurrentItem(currentStartupDisplayProfileListItem);
  1569. }
  1570. else {
  1571. base->startupDisplayProfileList->setCurrentItem(0);
  1572. }
  1573. createHotplugRulesGrid();
  1574. }
  1575. void KDisplayConfig::processDPMSControls() {
  1576. if (base->systemEnableDPMS->isChecked()) {
  1577. base->systemEnableDPMSStandby->setEnabled(true);
  1578. base->systemEnableDPMSSuspend->setEnabled(true);
  1579. base->systemEnableDPMSPowerDown->setEnabled(true);
  1580. base->dpmsStandbyTimeout->setEnabled(base->systemEnableDPMSStandby->isChecked());
  1581. base->dpmsSuspendTimeout->setEnabled(base->systemEnableDPMSSuspend->isChecked());
  1582. base->dpmsPowerDownTimeout->setEnabled(base->systemEnableDPMSPowerDown->isChecked());
  1583. }
  1584. else {
  1585. base->systemEnableDPMSStandby->setEnabled(false);
  1586. base->systemEnableDPMSSuspend->setEnabled(false);
  1587. base->systemEnableDPMSPowerDown->setEnabled(false);
  1588. base->dpmsStandbyTimeout->setEnabled(false);
  1589. base->dpmsSuspendTimeout->setEnabled(false);
  1590. base->dpmsPowerDownTimeout->setEnabled(false);
  1591. }
  1592. if (base->systemEnableDPMSStandby->isChecked()) base->dpmsSuspendTimeout->setMinValue(base->dpmsStandbyTimeout->value());
  1593. else base->dpmsSuspendTimeout->setMinValue(1);
  1594. if (base->systemEnableDPMSSuspend->isChecked()) base->dpmsPowerDownTimeout->setMinValue(base->dpmsSuspendTimeout->value());
  1595. else if (base->systemEnableDPMSStandby->isChecked()) base->dpmsPowerDownTimeout->setMinValue(base->dpmsStandbyTimeout->value());
  1596. else base->dpmsPowerDownTimeout->setMinValue(1);
  1597. }
  1598. void KDisplayConfig::processLockoutControls() {
  1599. if (!systemconfig->checkConfigFilesWritable( true )) {
  1600. base->globalTab->setEnabled(false);
  1601. base->resolutionTab->setEnabled(false);
  1602. base->gammaTab->setEnabled(false);
  1603. base->powerTab->setEnabled(false);
  1604. base->displayProfileList->setEnabled(false);
  1605. base->addProfileButton->setEnabled(false);
  1606. base->renameProfileButton->setEnabled(false);
  1607. base->deleteProfileButton->setEnabled(false);
  1608. base->reloadProfileButton->setEnabled(false);
  1609. base->saveProfileButton->setEnabled(false);
  1610. base->activateProfileButton->setEnabled(false);
  1611. base->startupDisplayProfileList->setEnabled(false);
  1612. base->systemEnableStartupProfile->setEnabled(false);
  1613. base->groupProfileRules->setEnabled(false);
  1614. }
  1615. else {
  1616. base->globalTab->setEnabled(true);
  1617. if (base->systemEnableSupport->isChecked()) {
  1618. base->resolutionTab->setEnabled(true);
  1619. base->gammaTab->setEnabled(true);
  1620. base->powerTab->setEnabled(true);
  1621. base->displayProfileList->setEnabled(true);
  1622. base->addProfileButton->setEnabled(true);
  1623. base->renameProfileButton->setEnabled(true);
  1624. base->deleteProfileButton->setEnabled(true);
  1625. base->reloadProfileButton->setEnabled(true);
  1626. base->saveProfileButton->setEnabled(true);
  1627. base->activateProfileButton->setEnabled(true);
  1628. base->systemEnableStartupProfile->setEnabled(true);
  1629. base->groupProfileRules->setEnabled(true);
  1630. if (base->systemEnableStartupProfile->isChecked()) {
  1631. base->startupDisplayProfileList->setEnabled(true);
  1632. }
  1633. else {
  1634. base->startupDisplayProfileList->setEnabled(false);
  1635. }
  1636. }
  1637. else {
  1638. base->resolutionTab->setEnabled(false);
  1639. base->gammaTab->setEnabled(false);
  1640. base->powerTab->setEnabled(false);
  1641. base->displayProfileList->setEnabled(false);
  1642. base->addProfileButton->setEnabled(false);
  1643. base->renameProfileButton->setEnabled(false);
  1644. base->deleteProfileButton->setEnabled(false);
  1645. base->reloadProfileButton->setEnabled(false);
  1646. base->saveProfileButton->setEnabled(false);
  1647. base->activateProfileButton->setEnabled(false);
  1648. base->startupDisplayProfileList->setEnabled(false);
  1649. base->systemEnableStartupProfile->setEnabled(false);
  1650. base->groupProfileRules->setEnabled(false);
  1651. }
  1652. }
  1653. base->loadExistingProfile->setEnabled(false); // Disable this until it works properly!
  1654. base->loadExistingProfile->hide(); // Same as above
  1655. }
  1656. TDECModule* KDisplayConfig::addTab( const TQString name, const TQString label )
  1657. {
  1658. // [FIXME] This is incomplete...Apply may not work...
  1659. TQWidget *page = new TQWidget( base->mainTabContainerWidget, name.latin1() );
  1660. TQVBoxLayout *top = new TQVBoxLayout( page, KDialog::marginHint() );
  1661. TDECModule *kcm = TDECModuleLoader::loadModule( name, page );
  1662. if ( kcm )
  1663. {
  1664. top->addWidget( kcm );
  1665. base->mainTabContainerWidget->addTab( page, label );
  1666. connect( kcm, TQT_SIGNAL( changed(bool) ), this, TQT_SLOT( changed() ) );
  1667. //m_modules.insert(kcm, false);
  1668. return kcm;
  1669. }
  1670. else {
  1671. delete page;
  1672. return NULL;
  1673. }
  1674. }
  1675. void KDisplayConfig::load(bool useDefaults )
  1676. {
  1677. if (getuid() != 0) {
  1678. availableProfileNames = m_randrsimple->getDisplayConfigurationProfiles(locateLocal("config", "/", true));
  1679. }
  1680. else {
  1681. availableProfileNames = m_randrsimple->getDisplayConfigurationProfiles(KDE_CONFDIR);
  1682. }
  1683. profileListChanged();
  1684. // Update the toggle buttons with the current configuration
  1685. updateArray();
  1686. if (getuid() != 0) {
  1687. base->systemEnableSupport->setChecked(m_randrsimple->getDisplayConfigurationEnabled(locateLocal("config", "/", true)));
  1688. base->systemEnableStartupProfile->setChecked(m_randrsimple->getDisplayConfigurationStartupAutoApplyEnabled(locateLocal("config", "/", true)));
  1689. startupProfileName = m_randrsimple->getDisplayConfigurationStartupAutoApplyName(locateLocal("config", "/", true));
  1690. }
  1691. else {
  1692. base->systemEnableStartupProfile->setChecked(m_randrsimple->getDisplayConfigurationStartupAutoApplyEnabled(KDE_CONFDIR));
  1693. base->systemEnableSupport->setChecked(m_randrsimple->getDisplayConfigurationEnabled(KDE_CONFDIR));
  1694. startupProfileName = m_randrsimple->getDisplayConfigurationStartupAutoApplyName(KDE_CONFDIR);
  1695. }
  1696. updateStartupProfileLabel();
  1697. refreshDisplayedInformation();
  1698. gammaselectScreen(base->gammamonitorDisplaySelectDD->currentItem());
  1699. base->gammaTargetSelectDD->clear();
  1700. base->gammaTargetSelectDD->insertItem("1.4", 0);
  1701. base->gammaTargetSelectDD->insertItem("1.6", 1);
  1702. base->gammaTargetSelectDD->insertItem("1.8", 2);
  1703. base->gammaTargetSelectDD->insertItem("2.0", 3);
  1704. base->gammaTargetSelectDD->insertItem("2.2", 4);
  1705. base->gammaTargetSelectDD->insertItem("2.4", 5);
  1706. base->gammaTargetSelectDD->setCurrentItem(4);
  1707. gammaTargetChanged(4);
  1708. if (getuid() != 0) {
  1709. currentHotplugRules = m_randrsimple->getHotplugRules(locateLocal("config", "/", true));
  1710. }
  1711. else {
  1712. currentHotplugRules = m_randrsimple->getHotplugRules(KDE_CONFDIR);
  1713. }
  1714. createHotplugRulesGrid();
  1715. emit changed(useDefaults);
  1716. }
  1717. void KDisplayConfig::saveActiveSystemWideProfileToDisk()
  1718. {
  1719. if (getuid() != 0) {
  1720. m_randrsimple->saveDisplayConfiguration(base->systemEnableSupport->isChecked(), base->systemEnableStartupProfile->isChecked(), activeProfileName, startupProfileName, locateLocal("config", "/", true), m_screenInfoArray[activeProfileName]);
  1721. }
  1722. else {
  1723. m_randrsimple->saveDisplayConfiguration(base->systemEnableSupport->isChecked(), base->systemEnableStartupProfile->isChecked(), activeProfileName, startupProfileName, KDE_CONFDIR, m_screenInfoArray[activeProfileName]);
  1724. }
  1725. }
  1726. void KDisplayConfig::save()
  1727. {
  1728. if (m_randrsimple->applyDisplayConfiguration(m_screenInfoArray[activeProfileName], TRUE)) {
  1729. saveActiveSystemWideProfileToDisk();
  1730. updateProfileConfigObjectFromGrid();
  1731. if (getuid() != 0) {
  1732. m_randrsimple->saveHotplugRules(currentHotplugRules, locateLocal("config", "/", true));
  1733. }
  1734. else {
  1735. m_randrsimple->saveHotplugRules(currentHotplugRules, KDE_CONFDIR);
  1736. }
  1737. // Write system configuration
  1738. systemconfig->setGroup(NULL);
  1739. systemconfig->writeEntry("EnableDisplayControl", base->systemEnableSupport->isChecked());
  1740. systemconfig->writeEntry("EnableAutoStartProfile", base->systemEnableStartupProfile->isChecked());
  1741. systemconfig->writeEntry("StartupProfileName", startupProfileName);
  1742. systemconfig->sync();
  1743. if (iccTab) {
  1744. iccTab->save();
  1745. }
  1746. emit changed(false);
  1747. }
  1748. else {
  1749. // Signal that settings were NOT applied
  1750. TQTimer *t = new TQTimer( this );
  1751. connect(t, SIGNAL(timeout()), SLOT(changed()) );
  1752. t->start( 100, FALSE );
  1753. }
  1754. }
  1755. void KDisplayConfig::defaults()
  1756. {
  1757. load( true );
  1758. }
  1759. TQString KDisplayConfig::quickHelp() const
  1760. {
  1761. return i18n("<h1>Monitor & Display Configuration</h1> This module allows you to configure monitors attached to your"
  1762. " computer via TDE.");
  1763. }
  1764. #include "displayconfig.moc"