randr.h
00001 /* 00002 * Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef __RANDR_H__ 00020 #define __RANDR_H__ 00021 00022 #include <tqobject.h> 00023 #include <tqstringlist.h> 00024 #include <tqptrlist.h> 00025 00026 #include <kcmodule.h> 00027 #include <kconfig.h> 00028 00029 class KTimerDialog; 00030 class RandRScreenPrivate; 00031 00032 struct SingleScreenData { 00033 TQString screenFriendlyName; 00034 bool generic_screen_detected; 00035 bool screen_connected; 00036 00037 TQStringList resolutions; 00038 TQStringList refresh_rates; 00039 TQStringList color_depths; 00040 TQStringList rotations; 00041 00042 int current_resolution_index; 00043 int current_refresh_rate_index; 00044 int current_color_depth_index; 00045 00046 float gamma_red; 00047 float gamma_green; 00048 float gamma_blue; 00049 00050 int current_rotation_index; 00051 int current_orientation_mask; 00052 bool has_x_flip; 00053 bool has_y_flip; 00054 bool supports_transformations; 00055 00056 bool is_primary; 00057 bool is_extended; 00058 int absolute_x_position; 00059 int absolute_y_position; 00060 int current_x_pixel_count; 00061 int current_y_pixel_count; 00062 00063 bool has_dpms; 00064 bool enable_dpms; 00065 unsigned int dpms_standby_delay; 00066 unsigned int dpms_suspend_delay; 00067 unsigned int dpms_off_delay; 00068 }; 00069 00070 class RandRScreen : public TQObject 00071 { 00072 Q_OBJECT 00073 00074 public: 00075 enum orientations { 00076 Rotate0 = 0x1, 00077 Rotate90 = 0x2, 00078 Rotate180 = 0x4, 00079 Rotate270 = 0x8, 00080 RotateMask = 15, 00081 RotationCount = 4, 00082 ReflectX = 0x10, 00083 ReflectY = 0x20, 00084 ReflectMask = 48, 00085 OrientationMask = 63, 00086 OrientationCount = 6 00087 }; 00088 00089 RandRScreen(int screenIndex); 00090 ~RandRScreen(); 00091 00092 void loadSettings(); 00093 void setOriginal(); 00094 00095 bool applyProposed(); 00096 00100 bool applyProposedAndConfirm(); 00101 00102 public slots: 00103 bool confirm(); 00104 bool showTestConfigurationDialog(); 00105 00106 public: 00107 TQString changedMessage() const; 00108 00109 bool changedFromOriginal() const; 00110 void proposeOriginal(); 00111 00112 bool proposedChanged() const; 00113 00114 static TQString rotationName(int rotation, bool pastTense = false, bool capitalised = true); 00115 TQPixmap rotationIcon(int rotation) const; 00116 TQString currentRotationDescription() const; 00117 00118 int rotationIndexToDegree(int rotation) const; 00119 int rotationDegreeToIndex(int degree) const; 00120 00124 TQStringList refreshRates(int size) const; 00125 00126 TQString refreshRateDirectDescription(int rate) const; 00127 TQString refreshRateIndirectDescription(int size, int index) const; 00128 TQString refreshRateDescription(int size, int index) const; 00129 00130 int currentRefreshRate() const; 00131 TQString currentRefreshRateDescription() const; 00132 00133 // Refresh rate hz <==> index conversion 00134 int refreshRateHzToIndex(int size, int hz) const; 00135 int refreshRateIndexToHz(int size, int index) const; 00136 00140 int numSizes() const; 00141 const TQSize& pixelSize(int index) const; 00142 const TQSize& mmSize(int index) const; 00143 int pixelCount(int index) const; 00144 00151 int sizeIndex(TQSize pixelSize) const; 00152 00153 int rotations() const; 00154 00158 int currentPixelWidth() const; 00159 int currentPixelHeight() const; 00160 int currentMMWidth() const; 00161 int currentMMHeight() const; 00162 00163 int currentRotation() const; 00164 int currentSize() const; 00165 00169 int proposedSize() const; 00170 bool proposeSize(int newSize); 00171 00172 int proposedRotation() const; 00173 void proposeRotation(int newRotation); 00174 00175 int proposedRefreshRate() const; 00183 bool proposeRefreshRate(int index); 00184 00188 void load(KConfig& config); 00189 void save(KConfig& config) const; 00190 00191 private: 00192 RandRScreenPrivate* d; 00193 00194 int m_screen; 00195 00196 TQValueList<TQSize> m_pixelSizes; 00197 TQValueList<TQSize> m_mmSizes; 00198 int m_rotations; 00199 00200 int m_originalRotation; 00201 int m_originalSize; 00202 int m_originalRefreshRate; 00203 00204 int m_currentRotation; 00205 int m_currentSize; 00206 int m_currentRefreshRate; 00207 00208 int m_proposedRotation; 00209 int m_proposedSize; 00210 int m_proposedRefreshRate; 00211 00212 KTimerDialog* m_shownDialog; 00213 00214 private slots: 00215 void desktopResized(); 00216 void shownDialogDestroyed(); 00217 }; 00218 00219 typedef TQPtrList<RandRScreen> ScreenList; 00220 00221 class RandRDisplay 00222 { 00223 public: 00224 RandRDisplay(); 00225 00226 bool isValid() const; 00227 const TQString& errorCode() const; 00228 const TQString& version() const; 00229 00230 int eventBase() const; 00231 int screenChangeNotifyEvent() const; 00232 int errorBase() const; 00233 00234 int screenIndexOfWidget(TQWidget* widget); 00235 00236 int numScreens() const; 00237 RandRScreen* screen(int index); 00238 00239 void setCurrentScreen(int index); 00240 int currentScreenIndex() const; 00241 RandRScreen* currentScreen(); 00242 00243 void refresh(); 00244 00252 bool loadDisplay(KConfig& config, bool loadScreens = true); 00253 void saveDisplay(KConfig& config, bool applyOnStartup, bool syncTrayApp); 00254 00255 static bool applyOnStartup(KConfig& config); 00256 static bool syncTrayApp(KConfig& config); 00257 00258 void applyProposed(bool confirm = true); 00259 00260 bool showTestConfigurationDialog(); 00261 00262 private: 00263 int m_numScreens; 00264 int m_currentScreenIndex; 00265 RandRScreen* m_currentScreen; 00266 ScreenList m_screens; 00267 00268 bool m_valid; 00269 QString m_errorCode; 00270 QString m_version; 00271 00272 int m_eventBase; 00273 int m_errorBase; 00274 }; 00275 00276 #endif