mirror of
https://github.com/fltk/fltk.git
synced 2026-06-05 16:12:13 +08:00
Cache screen information.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4224 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+37
-69
@@ -32,11 +32,28 @@
|
|||||||
|
|
||||||
#ifdef HAVE_XINERAMA
|
#ifdef HAVE_XINERAMA
|
||||||
# include <X11/extensions/Xinerama.h>
|
# include <X11/extensions/Xinerama.h>
|
||||||
|
|
||||||
|
static int num_screens = 0;
|
||||||
|
static XineramaScreenInfo *screens;
|
||||||
|
|
||||||
|
static void xinerama_init() {
|
||||||
|
if (!fl_display) fl_open_display();
|
||||||
|
|
||||||
|
if (XineramaIsActive(fl_display)) {
|
||||||
|
screens = XineramaQueryScreens(fl_display, &num_screens);
|
||||||
|
} else num_screens = 1;
|
||||||
|
}
|
||||||
#endif // HAVE_XINERAMA
|
#endif // HAVE_XINERAMA
|
||||||
|
|
||||||
|
|
||||||
// Return the number of screens...
|
// Return the number of screens...
|
||||||
int Fl::screen_count() {
|
int Fl::screen_count() {
|
||||||
|
#ifdef WIN32
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#elif defined(HAVE_XINERAMA);
|
||||||
|
if (!num_screens) xinerama_init();
|
||||||
|
return num_screens;
|
||||||
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the screen bounding rect for the given mouse position...
|
// Return the screen bounding rect for the given mouse position...
|
||||||
@@ -44,43 +61,23 @@ void Fl::screen_xywh(int &x, int &y, int &w, int &h, int mx, int my) {
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#elif defined(HAVE_XINERAMA)
|
#elif defined(HAVE_XINERAMA)
|
||||||
if (!fl_display) fl_open_display();
|
if (!num_screens) xinerama_init();
|
||||||
|
|
||||||
if (XineramaIsActive(fl_display)) {
|
if (num_screens > 0) {
|
||||||
int i,
|
int i;
|
||||||
num_rects;
|
|
||||||
XineramaScreenInfo *rects;
|
|
||||||
|
|
||||||
|
for (i = 0; i < num_screens; i ++) {
|
||||||
rects = XineramaQueryScreens(fl_display, &num_rects);
|
if (mx >= screens[i].x_org &&
|
||||||
|
mx < (screens[i].x_org + screens[i].width) &&
|
||||||
# ifdef DEBUG
|
my >= screens[i].y_org &&
|
||||||
printf("num_rects = %d\n", num_rects);
|
my < (screens[i].y_org + screens[i].height)) {
|
||||||
printf("window_->x_root() = %d, y_root() = %d\n",
|
x = screens[i].x_org;
|
||||||
window_->x_root(), window_->y_root());
|
y = screens[i].y_org;
|
||||||
# endif // DEBUG
|
w = screens[i].width;
|
||||||
|
h = screens[i].height;
|
||||||
for (i = 0; i < num_rects; i ++) {
|
return;
|
||||||
# ifdef DEBUG
|
|
||||||
printf("rects[%d] = [%d %d %d %d]\n", i,
|
|
||||||
rects[i].x_org, rects[i].y_org, rects[i].width,
|
|
||||||
rects[i].height);
|
|
||||||
# endif // DEBUG
|
|
||||||
|
|
||||||
if (mx >= rects[i].x_org &&
|
|
||||||
mx < (rects[i].x_org + rects[i].width) &&
|
|
||||||
my >= rects[i].y_org &&
|
|
||||||
my < (rects[i].y_org + rects[i].height))
|
|
||||||
{
|
|
||||||
x = rects[i].x_org;
|
|
||||||
y = rects[i].y_org;
|
|
||||||
w = rects[i].width;
|
|
||||||
h = rects[i].height;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(rects);
|
|
||||||
}
|
}
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
@@ -95,43 +92,14 @@ void Fl::screen_xywh(int &x, int &y, int &w, int &h, int n) {
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#elif defined(HAVE_XINERAMA)
|
#elif defined(HAVE_XINERAMA)
|
||||||
if (!fl_display) fl_open_display();
|
if (!num_screens) xinerama_init();
|
||||||
|
|
||||||
if (XineramaIsActive(fl_display)) {
|
if (num_screens > 0 && n < num_screens) {
|
||||||
int i,
|
x = screens[n].x_org;
|
||||||
num_rects;
|
y = screens[n].y_org;
|
||||||
XineramaScreenInfo *rects;
|
w = screens[n].width;
|
||||||
|
h = screens[n].height;
|
||||||
|
return;
|
||||||
rects = XineramaQueryScreens(fl_display, &num_rects);
|
|
||||||
|
|
||||||
# ifdef DEBUG
|
|
||||||
printf("num_rects = %d\n", num_rects);
|
|
||||||
printf("window_->x_root() = %d, y_root() = %d\n",
|
|
||||||
window_->x_root(), window_->y_root());
|
|
||||||
# endif // DEBUG
|
|
||||||
|
|
||||||
for (i = 0; i < num_rects; i ++) {
|
|
||||||
# ifdef DEBUG
|
|
||||||
printf("rects[%d] = [%d %d %d %d]\n", i,
|
|
||||||
rects[i].x_org, rects[i].y_org, rects[i].width,
|
|
||||||
rects[i].height);
|
|
||||||
# endif // DEBUG
|
|
||||||
|
|
||||||
if (mx >= rects[i].x_org &&
|
|
||||||
mx < (rects[i].x_org + rects[i].width) &&
|
|
||||||
my >= rects[i].y_org &&
|
|
||||||
my < (rects[i].y_org + rects[i].height))
|
|
||||||
{
|
|
||||||
x = rects[i].x_org;
|
|
||||||
y = rects[i].y_org;
|
|
||||||
w = rects[i].width;
|
|
||||||
h = rects[i].height;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree(rects);
|
|
||||||
}
|
}
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user