#include <display.hh>
Collaboration diagram for otk::Display:
Definition at line 20 of file display.hh.
Public Methods | |
Display () | |
Initializes the class, opens the X display. | |
~Display () | |
Destroys the class, closes the X display. | |
const ScreenInfo * | screenInfo (int snum) const |
Gets information on a specific screen. | |
const ScreenInfo * | findScreen (Window root) const |
Find a ScreenInfo based on a root window. | |
const RenderControl * | renderControl (int snum) const |
Gets the RenderControl for a screen. | |
bool | xkb () const |
Returns if the display has the xkb extension available. | |
int | xkbEventBase () const |
Returns the xkb extension's event base. | |
bool | shape () const |
Returns if the display has the shape extension available. | |
int | shapeEventBase () const |
Returns the shape extension's event base. | |
bool | xinerama () const |
Returns if the display has the xinerama extension available. | |
unsigned int | numLockMask () const |
unsigned int | scrollLockMask () const |
const XModifierKeymap * | modifierMap () const |
inline::Display * | operator * () const |
bool | ignoreErrors () const |
When true, X errors will be ignored. | |
void | setIgnoreErrors (bool t) |
Set whether X errors should be ignored. Use with care. | |
void | grab () |
Grabs the display. | |
void | ungrab () |
Ungrabs the display. | |
void | grabButton (unsigned int button, unsigned int modifiers, Window grab_window, bool owner_events, unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor, bool allow_scroll_lock) const |
void | ungrabButton (unsigned int button, unsigned int modifiers, Window grab_window) const |
void | grabKey (unsigned int keycode, unsigned int modifiers, Window grab_window, bool owner_events, int pointer_mode, int keyboard_mode, bool allow_scroll_lock) const |
void | ungrabKey (unsigned int keycode, unsigned int modifiers, Window grab_window) const |
Private Attributes | |
::Display * | _display |
The X display. | |
bool | _xkb |
Does the display have the XKB extension? | |
int | _xkb_event_basep |
Base for events for the XKB extension. | |
bool | _shape |
Does the display have the Shape extension? | |
int | _shape_event_basep |
Base for events for the Shape extension. | |
bool | _xinerama |
Does the display have the Xinerama extension? | |
int | _xinerama_event_basep |
Base for events for the Xinerama extension. | |
unsigned int | _mask_list [8] |
A list of all possible combinations of keyboard lock masks. | |
unsigned int | _num_lock_mask |
The value of the mask for the NumLock modifier. | |
unsigned int | _scroll_lock_mask |
The value of the mask for the ScrollLock modifier. | |
XModifierKeymap * | _modmap |
The key codes for the modifier keys. | |
int | _grab_count |
The number of requested grabs on the display. | |
bool | _ignore_errors |
When true, X errors will be ignored. Use with care. | |
ScreenInfo ** | _screeninfo_list |
A list of information for all screens on the display. | |
RenderControl ** | _rendercontrol_list |
A list of RenderControl objects, which are used for all graphics on a screen. |
|
Initializes the class, opens the X display. The DISPLAY environment variable is used to choose the display.
Definition at line 75 of file display.cc. References _, _display, _mask_list, _modmap, _num_lock_mask, _rendercontrol_list, _screeninfo_list, _scroll_lock_mask, _shape, _xinerama, _xkb, otk::display, and otk::putenv().
00076 : _display(0), 00077 _xkb(false), 00078 _xkb_event_basep(0), 00079 _shape(false), 00080 _shape_event_basep(0), 00081 _xinerama(false), 00082 _xinerama_event_basep(0), 00083 _mask_list(), 00084 _num_lock_mask(0), 00085 _scroll_lock_mask(0), 00086 _grab_count(0), 00087 _screeninfo_list(0), 00088 _rendercontrol_list(0) 00089 { 00090 int junk; 00091 (void)junk; 00092 00093 display = this; 00094 00095 // Open the X display 00096 if (!(_display = XOpenDisplay(NULL))) { 00097 printf(_("Unable to open connection to the X server. Please set the \n\ 00098 DISPLAY environment variable approriately.\n\n")); 00099 ::exit(1); 00100 } 00101 if (fcntl(ConnectionNumber(_display), F_SETFD, 1) == -1) { 00102 printf(_("Couldn't mark display connection as close-on-exec.\n\n")); 00103 ::exit(1); 00104 } 00105 if (!XSupportsLocale()) 00106 printf(_("X server does not support locale.\n")); 00107 if (!XSetLocaleModifiers("")) 00108 printf(_("Cannot set locale modifiers for the X server.\n")); 00109 00110 // set our error handler for X errors 00111 XSetErrorHandler(xerrorHandler); 00112 00113 // set the DISPLAY environment variable for any lauched children, to the 00114 // display we're using, so they open in the right place. 00115 putenv(std::string("DISPLAY=") + DisplayString(_display)); 00116 00117 // find the availability of X extensions we like to use 00118 #ifdef XKB 00119 _xkb = XkbQueryExtension(_display, &junk, &_xkb_event_basep, &junk, NULL, 00120 NULL); 00121 #endif 00122 00123 #ifdef SHAPE 00124 _shape = XShapeQueryExtension(_display, &_shape_event_basep, &junk); 00125 #endif 00126 00127 #ifdef XINERAMA 00128 _xinerama = XineramaQueryExtension(_display, &_xinerama_event_basep, &junk); 00129 #endif // XINERAMA 00130 00131 // get lock masks that are defined by the display (not constant) 00132 _modmap = XGetModifierMapping(_display); 00133 assert(_modmap); 00134 if (_modmap && _modmap->max_keypermod > 0) { 00135 const int mask_table[] = { 00136 ShiftMask, LockMask, ControlMask, Mod1Mask, 00137 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask 00138 }; 00139 const size_t size = (sizeof(mask_table) / sizeof(mask_table[0])) * 00140 _modmap->max_keypermod; 00141 // get the values of the keyboard lock modifiers 00142 // Note: Caps lock is not retrieved the same way as Scroll and Num lock 00143 // since it doesn't need to be. 00144 const KeyCode num_lock = XKeysymToKeycode(_display, XK_Num_Lock); 00145 const KeyCode scroll_lock = XKeysymToKeycode(_display, XK_Scroll_Lock); 00146 00147 for (size_t cnt = 0; cnt < size; ++cnt) { 00148 if (! _modmap->modifiermap[cnt]) continue; 00149 00150 if (num_lock == _modmap->modifiermap[cnt]) 00151 _num_lock_mask = mask_table[cnt / _modmap->max_keypermod]; 00152 if (scroll_lock == _modmap->modifiermap[cnt]) 00153 _scroll_lock_mask = mask_table[cnt / _modmap->max_keypermod]; 00154 } 00155 } 00156 00157 _mask_list[0] = 0; 00158 _mask_list[1] = LockMask; 00159 _mask_list[2] = _num_lock_mask; 00160 _mask_list[3] = LockMask | _num_lock_mask; 00161 _mask_list[4] = _scroll_lock_mask; 00162 _mask_list[5] = _scroll_lock_mask | LockMask; 00163 _mask_list[6] = _scroll_lock_mask | _num_lock_mask; 00164 _mask_list[7] = _scroll_lock_mask | LockMask | _num_lock_mask; 00165 00166 // Get information on all the screens which are available, and create their 00167 // RenderControl 00168 _screeninfo_list = new ScreenInfo*[ScreenCount(_display)]; 00169 _rendercontrol_list = new RenderControl*[ScreenCount(_display)]; 00170 for (int i = 0; i < ScreenCount(_display); ++i) { 00171 _screeninfo_list[i] = new ScreenInfo(i); 00172 _rendercontrol_list[i] = RenderControl::getRenderControl(i); 00173 } 00174 } |
|
Destroys the class, closes the X display.
Definition at line 177 of file display.cc. References _grab_count, _rendercontrol_list, _screeninfo_list, and ungrab().
00178 { 00179 while (_grab_count > 0) 00180 ungrab(); 00181 00182 XFreeModifiermap(_modmap); 00183 00184 for (int i = 0; i < ScreenCount(_display); ++i) { 00185 delete _rendercontrol_list[i]; 00186 delete _screeninfo_list[i]; 00187 } 00188 delete [] _rendercontrol_list; 00189 delete [] _screeninfo_list; 00190 00191 XCloseDisplay(_display); 00192 } |
|
Find a ScreenInfo based on a root window.
Definition at line 203 of file display.cc. References _screeninfo_list, and otk::ScreenInfo::rootWindow().
00204 { 00205 for (int i = 0; i < ScreenCount(_display); ++i) 00206 if (_screeninfo_list[i]->rootWindow() == root) 00207 return _screeninfo_list[i]; 00208 return 0; 00209 } |
|
Grabs the display.
Definition at line 227 of file display.cc. References _grab_count.
00228 { 00229 if (_grab_count == 0) { 00230 XGrabServer(_display); 00231 XSync(_display, false); // make sure it kicks in 00232 } 00233 _grab_count++; 00234 } |
|
Definition at line 260 of file display.cc.
00265 { 00266 unsigned int length = (allow_scroll_lock) ? 8 / 2: 00267 8; 00268 for (size_t cnt = 0; cnt < length; ++cnt) 00269 XGrabButton(_display, button, modifiers | _mask_list[cnt], 00270 grab_window, owner_events, event_mask, pointer_mode, 00271 keyboard_mode, confine_to, cursor); 00272 } |
|
Definition at line 287 of file display.cc.
00291 { 00292 unsigned int length = (allow_scroll_lock) ? 8 / 2: 00293 8; 00294 for (size_t cnt = 0; cnt < length; ++cnt) 00295 XGrabKey(_display, keycode, modifiers | _mask_list[cnt], 00296 grab_window, owner_events, pointer_mode, keyboard_mode); 00297 } |
|
When true, X errors will be ignored.
Definition at line 110 of file display.hh. Referenced by otk::xerrorHandler().
00110 { return _ignore_errors; } |
|
Definition at line 105 of file display.hh.
00105 { return _modmap; } |
|
Definition at line 103 of file display.hh. Referenced by otk::EventDispatcher::dispatchEvents().
00103 { return _num_lock_mask; } |
|
Definition at line 107 of file display.hh.
00107 { return _display; } |
|
Gets the RenderControl for a screen.
Definition at line 212 of file display.cc. References _rendercontrol_list. Referenced by otk::Widget::render(), otk::Label::renderForeground(), and otk::FocusLabel::renderForeground().
00213 { 00214 assert(snum >= 0); 00215 assert(snum < (signed) ScreenCount(_display)); 00216 return _rendercontrol_list[snum]; 00217 } |
|
Gets information on a specific screen. Returns a ScreenInfo class, which contains information for a screen on the display.
Definition at line 195 of file display.cc. References _screeninfo_list. Referenced by otk::Widget::create(), otk::RenderColor::create(), otk::Surface::createObjects(), otk::TrueRenderControl::drawGradientBackground(), otk::RenderControl::drawRoot(), otk::RenderControl::getRenderControl(), otk::RenderStyle::RenderStyle(), and otk::TrueRenderControl::TrueRenderControl().
00196 { 00197 assert(snum >= 0); 00198 assert(snum < (signed) ScreenCount(_display)); 00199 return _screeninfo_list[snum]; 00200 } |
|
Definition at line 104 of file display.hh. Referenced by otk::EventDispatcher::dispatchEvents().
00104 { return _scroll_lock_mask; } |
|
Set whether X errors should be ignored. Use with care.
Definition at line 220 of file display.cc. References _ignore_errors. Referenced by otk::EventDispatcher::dispatch().
00221 { 00222 _ignore_errors = t; 00223 // sync up so that anything already sent is/isn't ignored! 00224 XSync(_display, false); 00225 } |
|
Returns if the display has the shape extension available.
Definition at line 97 of file display.hh.
00097 { return _shape; } |
|
Returns the shape extension's event base.
Definition at line 99 of file display.hh. Referenced by otk::EventHandler::handle().
00099 { return _shape_event_basep; } |
|
Ungrabs the display.
Definition at line 237 of file display.cc. References _grab_count. Referenced by ~Display().
00238 { 00239 if (_grab_count == 0) return; 00240 _grab_count--; 00241 if (_grab_count == 0) { 00242 XUngrabServer(_display); 00243 XFlush(_display); // ungrab as soon as possible 00244 } 00245 } |
|
Definition at line 279 of file display.cc.
00281 {
00282 for (size_t cnt = 0; cnt < 8; ++cnt)
00283 XUngrabButton(_display, button, modifiers | _mask_list[cnt],
00284 grab_window);
00285 }
|
|
Definition at line 299 of file display.cc.
00301 {
00302 for (size_t cnt = 0; cnt < 8; ++cnt)
00303 XUngrabKey(_display, keycode, modifiers | _mask_list[cnt],
00304 grab_window);
00305 }
|
|
Returns if the display has the xinerama extension available.
Definition at line 101 of file display.hh.
00101 { return _xinerama; } |
|
Returns if the display has the xkb extension available.
Definition at line 92 of file display.hh.
00092 { return _xkb; } |
|
Returns the xkb extension's event base.
Definition at line 94 of file display.hh. Referenced by otk::EventHandler::handle().
00094 { return _xkb_event_basep; } |
|
The X display.
Definition at line 24 of file display.hh. Referenced by Display(). |
|
The number of requested grabs on the display.
Definition at line 54 of file display.hh. Referenced by grab(), ungrab(), and ~Display(). |
|
When true, X errors will be ignored. Use with care.
Definition at line 57 of file display.hh. Referenced by setIgnoreErrors(). |
|
A list of all possible combinations of keyboard lock masks.
Definition at line 42 of file display.hh. Referenced by Display(). |
|
The key codes for the modifier keys.
Definition at line 51 of file display.hh. Referenced by Display(). |
|
The value of the mask for the NumLock modifier.
Definition at line 45 of file display.hh. Referenced by Display(). |
|
A list of RenderControl objects, which are used for all graphics on a screen.
Definition at line 64 of file display.hh. Referenced by Display(), renderControl(), and ~Display(). |
|
A list of information for all screens on the display.
Definition at line 60 of file display.hh. Referenced by Display(), findScreen(), screenInfo(), and ~Display(). |
|
The value of the mask for the ScrollLock modifier.
Definition at line 48 of file display.hh. Referenced by Display(). |
|
Does the display have the Shape extension?
Definition at line 32 of file display.hh. Referenced by Display(). |
|
Base for events for the Shape extension.
Definition at line 34 of file display.hh. |
|
Does the display have the Xinerama extension?
Definition at line 37 of file display.hh. Referenced by Display(). |
|
Base for events for the Xinerama extension.
Definition at line 39 of file display.hh. |
|
Does the display have the XKB extension?
Definition at line 27 of file display.hh. Referenced by Display(). |
|
Base for events for the XKB extension.
Definition at line 29 of file display.hh. |