A generic touchscreen calibration program for X.Org
Révision | 03dadf55109bd43d3380f040debe9f82f66f2f35 (tree) |
---|---|
l'heure | 2014-02-14 07:24:23 |
Auteur | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
Merge pull request #51 from kreijack/screen_size
Correct screen size detection
@@ -81,25 +81,12 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) | ||
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | -#ifdef HAVE_X11_XRANDR | |
85 | - // get screensize from xrandr | |
86 | - int nsizes; | |
87 | - XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); | |
88 | - if (nsizes != 0) { | |
89 | - Rotation current = 0; | |
90 | - XRRRotations(display, screen_num, ¤t); | |
91 | - bool rot = current & RR_Rotate_90 || current & RR_Rotate_270; | |
92 | - int width = rot ? randrsize->height : randrsize->width; | |
93 | - int height = rot ? randrsize->width : randrsize->height; | |
94 | - set_display_size(width, height); | |
95 | - } else { | |
96 | - set_display_size(DisplayWidth(display, screen_num), | |
97 | - DisplayHeight(display, screen_num)); | |
98 | - } | |
99 | -# else | |
100 | - set_display_size(DisplayWidth(display, screen_num), | |
101 | - DisplayHeight(display, screen_num)); | |
102 | -#endif | |
84 | + int width, height; | |
85 | + detect_display_size(width, height); | |
86 | + set_display_size(width, height); | |
87 | + | |
88 | + fprintf(stderr, "INFO: width=%d, height=%d\n", | |
89 | + display_width, display_height); | |
103 | 90 | |
104 | 91 | // parse geometry string |
105 | 92 | const char* geo = calibrator->get_geometry(); |
@@ -166,6 +153,42 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) | ||
166 | 153 | #endif |
167 | 154 | } |
168 | 155 | |
156 | +void GuiCalibratorX11::detect_display_size( int &width, int &height) { | |
157 | + | |
158 | +#ifdef HAVE_X11_XRANDR | |
159 | + // check that screensize did not change | |
160 | + int nsizes; | |
161 | + bool xrandr_ok = false; | |
162 | + XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); | |
163 | + if (nsizes != 0) { | |
164 | + Rotation current = 0; | |
165 | + XRRScreenConfiguration * sc; | |
166 | + | |
167 | + sc = XRRGetScreenInfo (display, RootWindow (display, screen_num)); | |
168 | + int current_size = XRRConfigCurrentConfiguration (sc, ¤t); | |
169 | + | |
170 | + if (current_size < nsizes) { | |
171 | + | |
172 | + XRRRotations(display, screen_num, ¤t); | |
173 | + randrsize += current_size; | |
174 | + | |
175 | + bool rot = current & RR_Rotate_90 || current & RR_Rotate_270; | |
176 | + width = rot ? randrsize->height : randrsize->width; | |
177 | + height = rot ? randrsize->width : randrsize->height; | |
178 | + xrandr_ok = true; | |
179 | + } | |
180 | + } | |
181 | + if (!xrandr_ok) { | |
182 | + width = DisplayWidth(display, screen_num); | |
183 | + height = DisplayHeight(display, screen_num); | |
184 | + } | |
185 | +#else | |
186 | + width = DisplayWidth(display, screen_num); | |
187 | + height = DisplayHeight(display, screen_num); | |
188 | +#endif | |
189 | + | |
190 | +} | |
191 | + | |
169 | 192 | GuiCalibratorX11::~GuiCalibratorX11() |
170 | 193 | { |
171 | 194 | XUngrabPointer(display, CurrentTime); |
@@ -195,24 +218,7 @@ void GuiCalibratorX11::redraw() | ||
195 | 218 | if (calibrator->get_geometry() == NULL) { |
196 | 219 | int width; |
197 | 220 | int height; |
198 | -#ifdef HAVE_X11_XRANDR | |
199 | - // check that screensize did not change | |
200 | - int nsizes; | |
201 | - XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); | |
202 | - if (nsizes != 0) { | |
203 | - Rotation current = 0; | |
204 | - XRRRotations(display, screen_num, ¤t); | |
205 | - bool rot = current & RR_Rotate_90 || current & RR_Rotate_270; | |
206 | - width = rot ? randrsize->height : randrsize->width; | |
207 | - height = rot ? randrsize->width : randrsize->height; | |
208 | - } else { | |
209 | - width = DisplayWidth(display, screen_num); | |
210 | - height = DisplayHeight(display, screen_num); | |
211 | - } | |
212 | -#else | |
213 | - width = DisplayWidth(display, screen_num); | |
214 | - height = DisplayHeight(display, screen_num); | |
215 | -#endif | |
221 | + detect_display_size(width, height); | |
216 | 222 | if (display_width != width || display_height != height) { |
217 | 223 | set_display_size(width, height); |
218 | 224 | } |
@@ -68,6 +68,7 @@ private: | ||
68 | 68 | void on_button_press_event(XEvent event); |
69 | 69 | |
70 | 70 | // Helper functions |
71 | + void detect_display_size(int &width, int &height); | |
71 | 72 | void set_display_size(int width, int height); |
72 | 73 | void redraw(); |
73 | 74 | void draw_message(const char* msg); |