From 94deb10b014a0f6bb27bc34a130b5c4df9ee764e Mon Sep 17 00:00:00 2001 From: fluxgen <fluxgen> Date: Sat, 10 May 2003 13:54:29 +0000 Subject: holds info about screen --- src/ScreenInfo.cc | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ScreenInfo.hh | 84 +++++++++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 src/ScreenInfo.cc create mode 100644 src/ScreenInfo.hh diff --git a/src/ScreenInfo.cc b/src/ScreenInfo.cc new file mode 100644 index 0000000..8e46bcf --- /dev/null +++ b/src/ScreenInfo.cc @@ -0,0 +1,235 @@ +// ScreenInfo.cc for fluxbox +// Copyright (c) 2003 Henrik Kinnunen (fluxgen<at>users.sourceforge.net) +// +// from BaseDisplay.cc in Blackbox 0.61.1 +// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: ScreenInfo.cc,v 1.1 2003/05/10 13:54:29 fluxgen Exp $ + +#include "ScreenInfo.hh" + +#include "App.hh" + +#include <X11/Xutil.h> + +ScreenInfo::ScreenInfo(int num) { + + Display * const disp = FbTk::App::instance()->display(); + screen_number = num; + + root_window = RootWindow(disp, screen_number); + depth = DefaultDepth(disp, screen_number); + + width = + WidthOfScreen(ScreenOfDisplay(disp, screen_number)); + height = + HeightOfScreen(ScreenOfDisplay(disp, screen_number)); + + // search for a TrueColor Visual... if we can't find one... we will use the + // default visual for the screen + XVisualInfo vinfo_template, *vinfo_return; + int vinfo_nitems; + + vinfo_template.screen = screen_number; + vinfo_template.c_class = TrueColor; + + visual = (Visual *) 0; + + if ((vinfo_return = XGetVisualInfo(disp, + VisualScreenMask | VisualClassMask, + &vinfo_template, &vinfo_nitems)) && + vinfo_nitems > 0) { + + for (int i = 0; i < vinfo_nitems; i++) { + if (depth < (vinfo_return + i)->depth) { + depth = (vinfo_return + i)->depth; + visual = (vinfo_return + i)->visual; + } + } + + XFree(vinfo_return); + } + + if (visual) { + m_colormap = XCreateColormap(disp, root_window, + visual, AllocNone); + } else { + visual = DefaultVisual(disp, screen_number); + m_colormap = DefaultColormap(disp, screen_number); + } + +#ifdef XINERAMA + // check if we have Xinerama extension enabled + if (XineramaIsActive(disp)) { + m_hasXinerama = true; + xineramaLastHead = 0; + xineramaInfos = + XineramaQueryScreens(disp, &xineramaNumHeads); + } else { + m_hasXinerama = false; + xineramaInfos = 0; // make sure we don't point anywhere we shouldn't + } +#endif // XINERAMA +} + +ScreenInfo::~ScreenInfo() { +#ifdef XINERAMA + if (m_hasXinerama) { // only free if we first had it + XFree(xineramaInfos); + xineramaInfos = 0; + } +#endif // XINERAMA +} + +#ifdef XINERAMA + +/** + Searches for the head at the coordinates + x,y. If it fails or Xinerama isn't + activated it'll return head nr 0 +*/ +unsigned int ScreenInfo::getHead(int x, int y) const { + + // is Xinerama extensions enabled? + if (hasXinerama()) { + // check if last head is still active + /* if ((xineramaInfos[xineramaLastHead].x_org <= x) && + ((xineramaInfos[xineramaLastHead].x_org + + xineramaInfos[xineramaLastHead].width) > x) && + (xineramaInfos[xineramaLastHead].y_org <= y) && + ((xineramaInfos[xineramaLastHead].y_org + + xineramaInfos[xineramaLastHead].height) > y)) { + return xineramaLastHead; + } else { */ + // go trough all the heads, and search + for (int i = 0; (signed) i < xineramaNumHeads; i++) { + if (xineramaInfos[i].x_org <= x && + (xineramaInfos[i].x_org + xineramaInfos[i].width) > x && + xineramaInfos[i].y_org <= y && + (xineramaInfos[i].y_org + xineramaInfos[i].height) > y) + // return (xineramaLastHead = i); + return i; + } + // } + } + + return 0; +} + +/** + Searches for the head that the pointer + currently is on, if it isn't found + the first one is returned +*/ +unsigned int ScreenInfo::getCurrHead(void) const { + + // is Xinerama extensions enabled? + if (hasXinerama()) { + int x, y, wX, wY; + unsigned int mask; + Window rRoot, rChild; + // get pointer cordinates + if ( (XQueryPointer(basedisplay->getXDisplay(), root_window, + &rRoot, &rChild, &x, &y, &wX, &wY, &mask)) != 0 ) { + return getHead(x, y); + } + } + + return 0; +} + +/** + @return the width of head +*/ +unsigned int ScreenInfo::getHeadWidth(unsigned int head) const { + + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { +#ifdef DEBUG + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; +#endif // DEBUG + return xineramaInfos[xineramaNumHeads - 1].width; + } else + return xineramaInfos[head].width; + } + + return getWidth(); + +} + +/** + @return the heigt of head +*/ +unsigned int ScreenInfo::getHeadHeight(unsigned int head) const { + + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { +#ifdef DEBUG + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; +#endif // DEBUG + return xineramaInfos[xineramaNumHeads - 1].height; + } else + return xineramaInfos[head].height; + } + + return getHeight(); +} + + +/** + @return the X start of head nr head +*/ +int ScreenInfo::getHeadX(unsigned int head) const { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { +#ifdef DEBUG + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; +#endif // DEBUG + return xineramaInfos[head = xineramaNumHeads - 1].x_org; + } else + return xineramaInfos[head].x_org; + } + + return 0; +} + +/** + @return the Y start of head +*/ +int ScreenInfo::getHeadY(unsigned int head) const { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { +#ifdef DEBUG + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; +#endif // DEBUG + return xineramaInfos[xineramaNumHeads - 1].y_org; + } else + return xineramaInfos[head].y_org; + } + + return 0; +} + +#endif // XINERAMA diff --git a/src/ScreenInfo.hh b/src/ScreenInfo.hh new file mode 100644 index 0000000..b167d47 --- /dev/null +++ b/src/ScreenInfo.hh @@ -0,0 +1,84 @@ +// ScreenInfo.hh for fluxbox +// Copyright (c) 2003 Henrik Kinnunen (fluxgen<at>users.sourceforge.net) +// +// from BaseDisplay.hh in Blackbox 0.61.1 +// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: ScreenInfo.hh,v 1.1 2003/05/10 13:54:29 fluxgen Exp $ + +#ifndef SCREENINFO_HH +#define SCREENINFO_HH + +#include <X11/Xlib.h> + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef XINERAMA +extern "C" { +#include <X11/extensions/Xinerama.h> +} +#endif // XINERAMA + +/// holds information about a screen +class ScreenInfo { +public: + explicit ScreenInfo(int screen_num); + ~ScreenInfo(); + + inline Visual *getVisual() const { return visual; } + inline Window getRootWindow() const { return root_window; } + inline Colormap colormap() const { return m_colormap; } + + inline int getDepth() const { return depth; } + inline int getScreenNumber() const { return screen_number; } + + inline unsigned int getWidth() const { return width; } + inline unsigned int getHeight() const { return height; } + +#ifdef XINERAMA + inline bool hasXinerama() const { return m_hasXinerama; } + inline int getNumHeads() const { return xineramaNumHeads; } + unsigned int getHead(int x, int y) const; + unsigned int getCurrHead() const; + unsigned int getHeadWidth(unsigned int head) const; + unsigned int getHeadHeight(unsigned int head) const; + int getHeadX(unsigned int head) const; + int getHeadY(unsigned int head) const; +#endif // XINERAMA + +private: + Visual *visual; + Window root_window; + Colormap m_colormap; + + int depth, screen_number; + unsigned int width, height; +#ifdef XINERAMA + bool m_hasXinerama; + int xineramaMajor, xineramaMinor, xineramaNumHeads, xineramaLastHead; + XineramaScreenInfo *xineramaInfos; +#endif // XINERAMA + +}; + +#endif // SCREENINFO_HH -- cgit v0.11.2