Skip to content

Commit

Permalink
Merge pull request #51 from kreijack/screen_size
Browse files Browse the repository at this point in the history
Correct screen size detection
  • Loading branch information
tias committed Feb 13, 2014
2 parents 76ab69c + 4a42d0b commit 03dadf5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
80 changes: 43 additions & 37 deletions src/gui/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,12 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)
}
}

#ifdef HAVE_X11_XRANDR
// get screensize from xrandr
int nsizes;
XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes);
if (nsizes != 0) {
Rotation current = 0;
XRRRotations(display, screen_num, &current);
bool rot = current & RR_Rotate_90 || current & RR_Rotate_270;
int width = rot ? randrsize->height : randrsize->width;
int height = rot ? randrsize->width : randrsize->height;
set_display_size(width, height);
} else {
set_display_size(DisplayWidth(display, screen_num),
DisplayHeight(display, screen_num));
}
# else
set_display_size(DisplayWidth(display, screen_num),
DisplayHeight(display, screen_num));
#endif
int width, height;
detect_display_size(width, height);
set_display_size(width, height);

fprintf(stderr, "INFO: width=%d, height=%d\n",
display_width, display_height);

// parse geometry string
const char* geo = calibrator->get_geometry();
Expand Down Expand Up @@ -166,6 +153,42 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)
#endif
}

void GuiCalibratorX11::detect_display_size( int &width, int &height) {

#ifdef HAVE_X11_XRANDR
// check that screensize did not change
int nsizes;
bool xrandr_ok = false;
XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes);
if (nsizes != 0) {
Rotation current = 0;
XRRScreenConfiguration * sc;

sc = XRRGetScreenInfo (display, RootWindow (display, screen_num));
int current_size = XRRConfigCurrentConfiguration (sc, &current);

if (current_size < nsizes) {

XRRRotations(display, screen_num, &current);
randrsize += current_size;

bool rot = current & RR_Rotate_90 || current & RR_Rotate_270;
width = rot ? randrsize->height : randrsize->width;
height = rot ? randrsize->width : randrsize->height;
xrandr_ok = true;
}
}
if (!xrandr_ok) {
width = DisplayWidth(display, screen_num);
height = DisplayHeight(display, screen_num);
}
#else
width = DisplayWidth(display, screen_num);
height = DisplayHeight(display, screen_num);
#endif

}

GuiCalibratorX11::~GuiCalibratorX11()
{
XUngrabPointer(display, CurrentTime);
Expand Down Expand Up @@ -195,24 +218,7 @@ void GuiCalibratorX11::redraw()
if (calibrator->get_geometry() == NULL) {
int width;
int height;
#ifdef HAVE_X11_XRANDR
// check that screensize did not change
int nsizes;
XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes);
if (nsizes != 0) {
Rotation current = 0;
XRRRotations(display, screen_num, &current);
bool rot = current & RR_Rotate_90 || current & RR_Rotate_270;
width = rot ? randrsize->height : randrsize->width;
height = rot ? randrsize->width : randrsize->height;
} else {
width = DisplayWidth(display, screen_num);
height = DisplayHeight(display, screen_num);
}
#else
width = DisplayWidth(display, screen_num);
height = DisplayHeight(display, screen_num);
#endif
detect_display_size(width, height);
if (display_width != width || display_height != height) {
set_display_size(width, height);
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/x11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GuiCalibratorX11
void on_button_press_event(XEvent event);

// Helper functions
void detect_display_size(int &width, int &height);
void set_display_size(int width, int height);
void redraw();
void draw_message(const char* msg);
Expand Down

0 comments on commit 03dadf5

Please sign in to comment.