| 1 | /////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: displayx11.cpp |
| 3 | // Purpose: Unix/X11 implementation of wxDisplay class |
| 4 | // Author: Brian Victor |
| 5 | // Modified by: |
| 6 | // Created: 12/05/02 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) wxWindows team |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "display.h" |
| 14 | #endif |
| 15 | |
| 16 | // For compilers that support precompilation, includes "wx.h". |
| 17 | #include "wx/wxprec.h" |
| 18 | |
| 19 | #ifdef __BORLANDC__ |
| 20 | #pragma hdrstop |
| 21 | #endif |
| 22 | |
| 23 | #include "wx/display.h" |
| 24 | |
| 25 | #ifndef WX_PRECOMP |
| 26 | #include "wx/dynarray.h" |
| 27 | #include "wx/gdicmn.h" |
| 28 | #include "wx/string.h" |
| 29 | #include "wx/utils.h" |
| 30 | #endif /* WX_PRECOMP */ |
| 31 | |
| 32 | #if wxUSE_DISPLAY |
| 33 | |
| 34 | /* These must be included after the wx files. Otherwise the Data macro in |
| 35 | * Xlibint.h conflicts with a function declaration in wx/list.h. */ |
| 36 | extern "C" { |
| 37 | #include <X11/Xlib.h> |
| 38 | #include <X11/Xlibint.h> |
| 39 | #include <X11/extensions/Xinerama.h> |
| 40 | } |
| 41 | |
| 42 | class wxDisplayUnixPriv |
| 43 | { |
| 44 | public: |
| 45 | wxRect m_rect; |
| 46 | int m_depth; |
| 47 | }; |
| 48 | |
| 49 | size_t wxDisplayBase::GetCount() |
| 50 | { |
| 51 | Display *disp = (Display*)wxGetDisplay(); |
| 52 | |
| 53 | if ( XineramaIsActive(disp) ) |
| 54 | { |
| 55 | XineramaScreenInfo *screenarr; |
| 56 | int numscreens; |
| 57 | screenarr = XineramaQueryScreens(disp, &numscreens); |
| 58 | XFree(screenarr); |
| 59 | return numscreens; |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | return 1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | int wxDisplayBase::GetFromPoint(const wxPoint &p) |
| 68 | { |
| 69 | Display *disp = (Display*)wxGetDisplay(); |
| 70 | |
| 71 | if ( XineramaIsActive(disp) ) |
| 72 | { |
| 73 | int which_screen = -1; |
| 74 | XineramaScreenInfo *screenarr; |
| 75 | int numscreens; |
| 76 | screenarr = XineramaQueryScreens(disp, &numscreens); |
| 77 | |
| 78 | int i; |
| 79 | for (i = 0; i < numscreens; ++i) |
| 80 | { |
| 81 | if (p.x >= screenarr[i].x_org && |
| 82 | p.x <= screenarr[i].x_org + screenarr[i].width && |
| 83 | p.y >= screenarr[i].y_org && |
| 84 | p.y <= screenarr[i].y_org + screenarr[i].height) |
| 85 | { |
| 86 | which_screen = i; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | XFree(screenarr); |
| 91 | return which_screen; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ), m_priv( new wxDisplayUnixPriv ) |
| 100 | { |
| 101 | Display *disp = (Display*)wxGetDisplay(); |
| 102 | |
| 103 | if ( XineramaIsActive(disp) ) |
| 104 | { |
| 105 | XineramaScreenInfo *screenarr; |
| 106 | int numscreens; |
| 107 | screenarr = XineramaQueryScreens(disp, &numscreens); |
| 108 | m_priv->m_rect = wxRect(screenarr[index].x_org, screenarr[index].y_org, |
| 109 | screenarr[index].width, screenarr[index].height); |
| 110 | m_priv->m_depth = DefaultDepth(disp, DefaultScreen(disp)); |
| 111 | XFree(screenarr); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | wxSize size = wxGetDisplaySize(); |
| 116 | m_priv->m_rect = wxRect(0, 0, size.GetWidth(), size.GetHeight()); |
| 117 | m_priv->m_depth = wxDisplayDepth(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | wxDisplay::~wxDisplay() |
| 122 | { |
| 123 | delete m_priv; |
| 124 | } |
| 125 | |
| 126 | wxRect wxDisplay::GetGeometry() const |
| 127 | { |
| 128 | return m_priv->m_rect; |
| 129 | } |
| 130 | |
| 131 | int wxDisplay::GetDepth() const |
| 132 | { |
| 133 | return m_priv->m_depth; |
| 134 | } |
| 135 | |
| 136 | wxString wxDisplay::GetName() const |
| 137 | { |
| 138 | return ""; |
| 139 | } |
| 140 | |
| 141 | #endif /* wxUSE_DISPLAY */ |
| 142 | |